Click here to Skip to main content
13,703,177 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 4 days ago
Updated 4 days ago

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  

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
Web06-2016 | 2.8.180906.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