Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want when the checkbox is unchecked to delete text off a variable
VB
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
Updated 15-Sep-18 23:55pm

1 solution

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[^]
 
Share this answer
 
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900