Click here to Skip to main content
13,765,990 members
Rate this:
 
Please Sign up or sign in to vote.
See more: , +
I want when the checkbox is unchecked to delete text off a variable
Imports System
Imports System.IO
Imports System.Text
Imports System.Environment

Public Class Form1

    Dim slowchecked As Boolean = False
    Dim filepath As String
    Dim code1 As String = ""
    Dim slowdown As String

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If slowchecked = False Then
            slowdown = ("start" & NewLine & "start" & NewLine & "start" & NewLine & "start" _
                & NewLine & "start" & NewLine & "start" & NewLine & "start crash" & NewLine)
            code1 = (code1 & slowdown)
            slowchecked = True
        ElseIf slowchecked = True Then
            Replace(code1, slowdown, "")
            MsgBox(code1)
            slowchecked = False
        End If
    End Sub
End Class


but it doesn't delete or come out with an error

What I have tried:

Tried swapping "Replace(code1, slowdown, "")" with "code1.Replace(slowdown, "")" but I don't know what else to try.
Posted 16-Sep-18 0:20am
Updated 16-Sep-18 0:55am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Yes it does. But not the way you are assuming it would.
Replace doesn't change strings, it returns a new string with the replacements done: Replace Function (VB6) - VB & VBA in a Nutshell: The Language [Book][^]
So you need to assign the result to a variable, or it is just discarded.

By the way: if you are going to use VB.NET, then you should stop using VB6 functions such as Replace and MsgBox, and use the .NET versions instead: String.Replace Method (System) | Microsoft Docs[^] and MessageBox.Show Method (System.Windows) | Microsoft Docs[^]
  Permalink  
Comments
Member 13985992 21-Sep-18 9:18am
   
I don't get it, what do you mean by assign result? Give me an example.
OriginalGriff 21-Sep-18 9:59am
   
What do you think? How would you normally assign a value to a variable?
Member 13985992 21-Sep-18 10:25am
   
I don't know! I'm a begginner
OriginalGriff 21-Sep-18 10:45am
   
So you've never even seen this:

noOfItems = 6

I find that difficult to believe...
Member 13985992 21-Sep-18 10:47am
   
still don't get it soz
why do i need it
OriginalGriff 21-Sep-18 10:59am
   
noOfItems = 6
    ^     ^ ^
    |     | |
    |     |  -- Value
    |      ---- Assignment operator
     ---------- Variable


Which part of this is giving you problems?
Member 13985992 21-Sep-18 11:01am
   
why do i need it?
OriginalGriff 21-Sep-18 11:08am
   
Follow the link and read what is says ... you are going to have to start thinking here - this is not a field where you can glide through without engaging your brain, you know.
Member 13985992 21-Sep-18 11:21am
   
i looked back at the comments and i misread your answer, i did assign a value to the var, just to make sure, what variable are you talking about?
OriginalGriff 21-Sep-18 11:26am
   
:sigh:

What is the title of your question?
HINT. HINT.
Member 13985992 21-Sep-18 12:05pm
   
DOESN'T WORK! That's the title of the question.
OriginalGriff 21-Sep-18 12:11pm
   
Oh FFS.

1) Engage brain.
2) Follow link in original solution.
3) Read. I know you can do that on your own ...
4) Find the bit where it says "Return Value" and pay loads of attention to what it says below that.
5) Possibly, think a bit.
6) Add a variable and an assignment operator to your code...
7) Profit ...:laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181114.1 | Last Updated 16 Sep 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100