Programming Assistance Thread

Website, internet, technology, and computer resources, discussion and assistance.

Unread postby Justin » Wed Jun 21, 2006 2:39 pm

what happens is the app when finished running returns control back to the dev ide and your output window closes. You need to pause the application or try running it from the command line to see your results.

To pause the app there are several solutions try

Code: Select all
system("PAUSE");  //this may be windows only!


or

Code: Select all
cout << "Press any key to continue..." << endl;
char ret = '';
getchar( ret );


The second option assumes you are using the std namespace and have included the iostream header class. Also it
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

Unread postby Pi Ka Chu » Wed Mar 19, 2008 5:19 pm

Can someone tell me what is wrong with my code. I am using Visual Basics 2005 and I keep getting first chance exception errors.
Code: Select all
Public Class Form1
    Dim strUsername(9) As String
    Dim strPassword(9) As String
    Dim intIndexCount As Integer = 0
    Dim strUserinput As String = CStr(txtUsername.Text)
    Dim strPassinput As String = CStr(txtPassword.Text)

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim strInputUsername As String
        Dim strInputPassword As String
        Dim intCount As Integer = 0
        Do While intCount < 9
            strInputUsername = CStr(InputBox("Username needed", "Username"))
            strUsername(intCount) = strInputUsername
            strInputPassword = CStr(InputBox("Password needed", "Password"))
            strUsername(intCount) = strInputPassword
            intCount += 1
        Loop


       


    End Sub
    Public Sub Varify(ByRef bolFound As Boolean)

        For intIndexCount = 0 To 9
            If strUsername(intIndexCount) = strUserinput And _
            strPassword(intIndexCount) Then
                bolFound = True
            Else
                bolFound = False
            End If
            intIndexCount = intIndexCount + 1
        Next intIndexCount



    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub

    Private Sub btnVarify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVarify.Click
        Dim Bolfound As Boolean
        Varify(bolFound)
        If bolFound = True Then
            MessageBox.Show("The password is correct", "Username Verified", MessageBoxButtons.OK)
        Else
            MessageBox.Show("The password is correct", "Username Verified", MessageBoxButtons.OK)

        End If
    End Sub
End Class
Nice guys don't insists on being creepers just because they were nice.
User avatar
Pi Ka Chu
Scholar of Shen Zhou
 
Posts: 738
Joined: Mon Jan 01, 2007 2:18 am
Location: Watching Ratatosk insult the eagle on Yggdrasil for the wrym Níðhöggr

Unread postby Justin » Wed Mar 19, 2008 5:45 pm

This is vb.net correct? I need the entire project to be able to try and debug/step through the code.
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

Unread postby Pi Ka Chu » Wed Mar 19, 2008 5:56 pm

Justin wrote:This is vb.net correct? I need the entire project to be able to try and debug/step through the code.

How do I send you that?
Nice guys don't insists on being creepers just because they were nice.
User avatar
Pi Ka Chu
Scholar of Shen Zhou
 
Posts: 738
Joined: Mon Jan 01, 2007 2:18 am
Location: Watching Ratatosk insult the eagle on Yggdrasil for the wrym Níðhöggr

Unread postby Justin » Wed Mar 19, 2008 6:46 pm

Well before you do that what exactly are you trying to do with this code?
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

Unread postby Justin » Wed Mar 19, 2008 7:00 pm

Code: Select all
Dim strUserinput As String = CStr(txtUsername.Text)
Dim strPassinput As String = CStr(txtPassword.Text)


This is your problem. You are trying to access a control (ie member of the Form1 class) that hasn't been created yet. It's a bad idea to access controls when declaring a class level variable. You will need to declare them as blank

Code: Select all
Dim strUserinput As String
Dim strPassinput As String


And then in the appropriate button handler or the verify function set those member variables using the text boxes. Also there is no need to use CStr when assigning the text property from a textbox to a string variable.

Code: Select all
strUserinput =  txtUsername.Text


Should work just fine.
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

Unread postby Pi Ka Chu » Wed Mar 19, 2008 7:14 pm

Justin wrote:
This is your problem. You are trying to access a control (ie member of the Form1 class) that hasn't been created yet. It's a bad idea to access controls when declaring a class level variable. You will need to declare them as blank

What does it mean to declare it blank. Sorry, it my final and I really need to do well on this program. Its a password varifier and the form needs to look like this:
Image
Nice guys don't insists on being creepers just because they were nice.
User avatar
Pi Ka Chu
Scholar of Shen Zhou
 
Posts: 738
Joined: Mon Jan 01, 2007 2:18 am
Location: Watching Ratatosk insult the eagle on Yggdrasil for the wrym Níðhöggr

Unread postby Justin » Wed Mar 19, 2008 7:28 pm

Your image is broken, either email it to me or talk to me on messenger.
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

Unread postby Pi Ka Chu » Wed Mar 19, 2008 7:57 pm

Justin wrote:Your image is broken, either email it to me or talk to me on messenger.

I have emailed to you. THANKS!!
Nice guys don't insists on being creepers just because they were nice.
User avatar
Pi Ka Chu
Scholar of Shen Zhou
 
Posts: 738
Joined: Mon Jan 01, 2007 2:18 am
Location: Watching Ratatosk insult the eagle on Yggdrasil for the wrym Níðhöggr

Unread postby Justin » Wed Mar 19, 2008 8:03 pm

Email sent but just in case this is the code you need to use. Tested and run on windows XP.

Code: Select all
Public Class Form1
    ' arrays used to hold usernames and passwords
    Dim strUsername(9) As String
    Dim strPassword(9) As String

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim strInputUsername As String
        Dim strInputPassword As String

        Dim intCount As Integer = 0

        Do While intCount < 9
            strInputUsername = CStr(InputBox("Username needed", "Username " + (intCount + 1).ToString()))
            strUsername(intCount) = strInputUsername
            strInputPassword = CStr(InputBox("Password needed", "Password " + (intCount + 1).ToString()))
            Me.strPassword(intCount) = strInputPassword
            intCount += 1
        Loop
    End Sub

    Public Sub Varify(ByRef bolFound As Boolean)
        Dim intIndexCount As Integer

        ' loop through the arrays and check if the current username/password match
        For intIndexCount = 0 To 9
            If strUsername(intIndexCount) = Me.txtUsername.Text And _
            strPassword(intIndexCount) = Me.txtPassword.Text Then
                bolFound = True
                ' we return true since we found a match
                Return
            Else
                bolFound = False
            End If
            intIndexCount = intIndexCount + 1
        Next intIndexCount
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub

    Private Sub btnVarify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVarify.Click
        Dim Bolfound As Boolean

        ' verify those values match values in the array
        Varify(bolFound)

        ' show the appropriate message
        If Bolfound = True Then
            MessageBox.Show("The username/password is correct", "Username Verified", MessageBoxButtons.OK)
        Else
            MessageBox.Show("The username/password is incorrect", "Username Verified", MessageBoxButtons.OK)

        End If
    End Sub
End Class
My Website

My Blog

The Dungeon

Trouble maker extraordinaire!
User avatar
Justin
Scholar of Shen Zhou
 
Posts: 3356
Joined: Fri Jun 21, 2002 2:08 am
Location: Dropping it like it's hot

PreviousNext

Return to Foreign Kingdoms

Who is online

Users browsing this forum: No registered users and 2 guests

Copyright © 2002–2008 Kongming’s Archives. All Rights Reserved