Results 1 to 11 of 11

Thread: "Array value", "Main()" and "wait user to press key" question. Please help!

  1. #1
    Junior Member
    Join Date
    Aug 12
    Posts
    29

    "Array value", "Main()" and "wait user to press key" question. Please help!

    Hi! I use Visual Basic 2010 Express. I am learning this now, and after a few days googling without any result. Please-please help:

    1) At the beginning of the program, I want to declare an array Pass(500) as Boolean and all has True value from the beginning.
    I don't want to declare one by one like this:
    Pass(1) as Boolean = True
    Pass(2) as Boolean = True
    etc...

    How can I do that? (I should use For I=1 to 500 : Pass(I)=True : Next I, but where?)
    Can I put in the Main() Procedure? If yes, how? If not, where should I put those lines?

    2) About Main(): I still don't know how to use Main()...it reacts differently than any other Procedure I made...
    I can't declare variable, I can't declare TextBox1.Text="Try try try". Always error. Why?
    How can I declare that? (I want to add "Try Try Try" to my TextBox1.Text at the beginning of the program. How? --> I don't want to add via the TextBox1 Property in the Design Tab, but I want to do it manually at the beginning of the program).

    3). How can I make the program wait until the user press a key?
    I have a TextBox and a RichTextBox.
    When the user type Quit in the TextBox & press enter, I will add "Are you sure ? (Y/N)" to the RichTextBox.
    Then I want the program to stop, waiting for the user to press Y or N (it will loop forever if the user press another button).
    Note: I know I can use MsgBox easily, but I don't want to use MsgBox.

    Thx alot!

  2. #2
    Member
    Join Date
    Mar 11
    Posts
    44

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    1)

    Code:
     
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim Pass As Boolean
    
            For I = 0 To 500
                'Based in the I index you can tell if pass is true or false
                If I = 12 Then
                    Pass = True
                End If
    
                If Pass = True Then
                    'Do something here
                End If
            Next
        End Sub
    End Class
    2)

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim Pass As Boolean
    
            For I = 0 To 500
                'Based in the I index you can tell if pass is true or false
                If I = 12 Then
                    Pass = True
                End If
    
                If Pass = True Then
                    'Do something here
                End If
            Next
    
            TextBox1.Text = "Try Try Try"
    
        End Sub
    End Class
    3)

    Code:
    Public Class Form1
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text = "Quit" Then
                RichTextBox1.Text = "Are you sure ? (Y/N)"
            End If
        End Sub
    
        Private Sub RichTextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseClick
            RichTextBox1.Clear()
        End Sub
    
        Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
            If RichTextBox1.Text = "Y" Or RichTextBox1.Text = "y" Then
                'Do something
            End If
    
            If RichTextBox1.Text = "N" Or RichTextBox1.Text = "n" Then
                'Do something
            End If
        End Sub
    End Class

  3. #3
    Member
    Join Date
    Mar 11
    Posts
    44

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    If you have any questions about anything in vb or related to this post please feel free to ask

  4. #4
    Junior Member
    Join Date
    Aug 12
    Posts
    29

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    1&2) Wow thank you, thank you! How can I miss that ? I have searched for this thing for a few days!!
    It's so easy: double click the Form and the Procedure will appear....

    3) Err.... I don't want the user to be able to type other things in the Text Box while waiting for the Y/N answer....
    Clarification (I don't want to use MsgBox):
    I have a TextBox and a RichTextBox. The user can type anything in the TextBox, then the RichTextBox(ReadOnly) will be working like a "screen".
    When the user type anything in TextBox & press Enter, the text will appear in the RichTextBox.

    If the user type QUIT in the TextBox & press Enter, the text in RichTextBox will be: "QUIT. Are you sure? (Y/N)"
    At this point I don't want the user be able to type anything again in the TextBox until he press Y or N. Basically I want the program to work like MsgBox : When an MsgBox appears, everything else is stopped, waiting for the user to click "YES" or "NO" button in the MessageBox.

    In Pascal (my old days) it can use something like "Repeat until Keypressed" or something so the program is locked until the user press a key. How to do that in this Event Driven programming?

    Thanks!

  5. #5
    Member
    Join Date
    Mar 11
    Posts
    44

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Hello,
    Why would you want to use enter and not read it automatically.
    This code will show Are you sure ? (Y/N) when you have completed to type Quit in the textbox
    Then you have to type Y or N in the RichTextBox and they you tell the programm to do something.
    I did not use any msgboxes.
    If you want to be able to type Y or N in the Textbox just chance the code a bit.

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    If TextBox1.Text = "Quit" Then
    RichTextBox1.Text = "Are you sure ? (Y/N)"
    End If
    End Sub

    Private Sub RichTextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseClick
    RichTextBox1.Clear()
    End Sub

    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    If RichTextBox1.Text = "Y" Or RichTextBox1.Text = "y" Then
    'Do something
    End If

    If RichTextBox1.Text = "N" Or RichTextBox1.Text = "n" Then
    'Do something
    End If

    If Not RichTextBox1.Text = "N" Or RichTextBox1.Text = "n" RichTextBox1.Text = "Y" Or RichTextBox1.Text = "y" Then
    RichTextBox1.Text = "Are you sure ? (Y/N)"
    End If
    End Sub

  6. #6
    Member
    Join Date
    Mar 11
    Posts
    44

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Add an TextBox, RichTextBox, and a Timer to your form
    Name TextBox - "TextBox1"
    Name RichTextBox - "RichTextBox1"
    Name Timer - "Timer1"
    (without the quotes)

    VB:
    Code:
    Public Class Form1
    
        Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            If e.KeyCode = Keys.Enter Then
                If TextBox1.Text = "Quit" Or TextBox1.Text = "quit" Then
                    RichTextBox1.Text = "Are you sure ? (Y/N)"
                    TextBox1.Text = ""
                End If
    
                If RichTextBox1.Text = "Are you sure ? (Y/N)" Then
                    If TextBox1.Text = "Y" Or TextBox1.Text = "y" Then
                        Timer1.Start()
                        Timer1.Enabled = True
                    End If
    
                    If TextBox1.Text = "N" Or TextBox1.Text = "n" Then
                        RichTextBox1.Text = "Appliction did not quit"
                    End If
                End If
            End If
    
            If RichTextBox1.Text = "Are you sure ? (Y/N)" And Not TextBox1.Text = "Y" Or TextBox1.Text = "y" And Not TextBox1.Text = "N" Or TextBox1.Text = "n" Then
                TextBox1.Clear()
            End If
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Static count As Integer
            If count < 1 Then
                RichTextBox1.Text = "Quitting."
                count += 1
            ElseIf count < 2 Then
                RichTextBox1.Text = "Quitting.."
                count += 1
            ElseIf count < 3 Then
                RichTextBox1.Text = "Quitting..."
                count += 1
            ElseIf count < 4 Then
                RichTextBox1.Text = "Quitting."
                count += 1
            ElseIf count < 5 Then
                RichTextBox1.Text = "Quitting.."
                count += 1
            ElseIf count < 6 Then
                RichTextBox1.Text = "Quitting..."
                count += 1
                Application.Exit()
            End If
        End Sub
    End Class
    Is this what you want?
    Last edited by pietercdevries; Aug 17th, 2012 at 12:16 PM.

  7. #7
    Junior Member
    Join Date
    Aug 12
    Posts
    29

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Ahhhhh thank you. Thank you...
    Problem solved. Continue the work....

    By the way : how to remove the automatic hyperlink created?
    Example: I add a line "Please check www.vbforums.com" to richtextbox, then the text "www.vbforums.com" becomes hyperlink instantly (user can click it). How to remove that?

  8. #8
    Member
    Join Date
    Mar 11
    Posts
    44

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Why are you using a richtextbox then?

  9. #9
    Hyperactive Member
    Join Date
    Jul 11
    Location
    UK
    Posts
    436

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    How a richtextbox handles URLs that are typed into the control is probably going to be a property of the RichTextBox Class. A good place to check for this is the MSDN documentation for the RichTextBox Class where you can find out what properties (and methods) the class exposes. You should be able to spot a property that determines how the richtextbox behaves when it detects URLs.

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,530

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Quote Originally Posted by Inferrd View Post
    How a richtextbox handles URLs that are typed into the control is probably going to be a property of the RichTextBox Class. A good place to check for this is the MSDN documentation for the RichTextBox Class where you can find out what properties (and methods) the class exposes. You should be able to spot a property that determines how the richtextbox behaves when it detects URLs.
    Er .. that would be ...

    RichTextBox1.DetectUrls = False

    ... then?

  11. #11
    Junior Member
    Join Date
    Aug 12
    Posts
    29

    Re: "Array value", "Main()" and "wait user to press key" question. Please help!

    Hi everyone!

    Thank you for the help!

    A short story: I was a hobbiist programmer around a decade ago (Pascal/VB/Delphi). In the last few days, I started to do programming again (again,as a hobby). So it's just like visiting an old friend

    At first I try to learn Java (what is the most popular programming language now? Java? Great! Let's learn that! ) but after two days, it's like banging my head on the wall. I need a long time just to try "Hello World"! Gosh! Am I stupid or what? It looks like I was drowned in a vast ocean, don't know what to do with sooo many options, keywords, etc.... Then I try VB (2010 Express edition), and feel like home!

    In this project I want to make a text adventure game (it's fantasy/RPG). Basically the OrderBox is the input and RichTextBox is the "screen". I try my best to mirror everything in a text adventure game (that's why no MsgBox, almost no mouse support, etc).
    So far with all your help above, everything is clear (Note: at last I don't use the Timer in RichTextBox but I use KeyUp and a variable ToQuit (I use your idea here)). Sometime what I was looking for is so clear (just like DetectUrls) but somehow I can't find it everywhere! Strange, eh...

    This will be (my assumption) around a month project. So if I hit another dead end, I will go back here (of course after asking Uncle Google first)

    Thank you! (I will put something like "Thanks to the VB Forum" after the game is ready )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •