Member Avatar for DyO1

Hello,

I need a code that will check if a certain text exist.
This is how it's now:

            If TextBox2.Text = ".sys\clock" Then
                TextBox1.Text = TextBox1.Text + Environment.NewLine + ("It's") + DateTime.Now
            End If

and I want to make something like this

            If TextBox2.Text = ".sys\clock" Then
                TextBox1.Text = TextBox1.Text + Environment.NewLine + ("It's") + DateTime.Now
            ElseIf .sys\ does not exist in textbox2 then show an error=
            Textbox1.text=("You didn't used the .SYS\ code")
            End If

I hope you understand...please, HELP ME ! :-(

It looks like you pretty much have it except for the Else (and you should use & instead of + to concatenate strings).

If TextBox2.Text = ".\sys\clock" Then
    TextBox1.Text = TextBox1.Text & Environment.NewLine & "It's " & DateTime.Now
Else
    Textbox1.text = "You didn't use the .SYS\ code"
End If
Member Avatar for DyO1

That will make the program to check if .sys\clock is in the textbox,all i want it to do is to make something like a command promps, .SYS\ will be used for system commands,and you have to be able to open TXT files by entering their path name,but i don't know what code to use,if i use yours i won't be able to use the path thingy,it will only check for .SYS\

And if you prompt for input and the user enters ".sys\" then what? Tell me what you are trying to do (never mind the code) and I'll try to help.

Member Avatar for DyO1

Something like my own dos,when you enter C:\texts\text it's going to read that file,WHATEVER format it is.
And for next version i want to add some built-in codes,the .sys\clock will tell the date and time,already made that but now i can't use the program to read the files,
need more info?

So if the text the user enters is a filename you want to display the file. I get that. And if it is not a file you want to compare it to a list of builtin codes. How about something like this

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        If My.Computer.FileSystem.FileExists(TextBox2.Text) Then
            DisplayFile(TextBox2.Text)
        ElseIf LCase(TextBox2.Text).StartsWith(".sys\") Then
            ExecuteCustomCommand(TextBox2.Text)
        Else
            MsgBox("file " & TextBox2.Text & " not found")
        End If

    End Sub

    Private Sub ExecuteCustomCommand(command As String)

        Select Case LCase(command)
            Case ".\sys\clock"
                TextBox1.AppendText(vbCrLf & "It's " & DateTime.Now)
            Case ".\sys\user"
                TextBox1.AppendText(vbCrLf & "You are " & Environment.UserName)
            Case Else
                MsgBox("invalid .sys\ command")
        End Select

    End Sub

    Private Sub DisplayFile(filename As String)
        'your code here
    End Sub
Member Avatar for DyO1

Thank you :D

Glad to help. If this thread is solved then please mark it as such.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.