Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Visual Basic (VB 4/5/6) » General Visual Basic » Help with homework


Help with homeworkExpand / Collapse
Author
Message
Posted 5/8/2008 11:43:18 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/12/2008 4:29:48 PM
Posts: 2, Visits: 15
Hi. I am stuck on this problem and I could not find an examples. Can someone help me with this? I really appreciate it. Thank you in advance.

Charge Account Validation:
Create an application that allows the user to enter a charge account number. The application should be determine whether the number is valid by comparing it to the numbers in the following list(there are more numbers but I'll just add to the code):
5658845
8080152
1005231
The list of numbers should be stored in an array. A sequential search should be used to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message indicating the number is valid. If the user enters a number that is not in the array, the program should display a message indicating the number is invalid.


dim Accounts() as integer= {5658845,8080152,1005231}

Post #24855
Posted 5/9/2008 10:43:13 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 4:36:16 PM
Posts: 1,463, Visits: 3,400
Welcome to A1vbcode Mike.

Well we won't do homework for you but we will help with any problems you have.

Which part are you having trouble with?

Putting the number into an array?

Checking the number entered in a TextBox with the numbers in the array?

Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #24858
Posted 5/10/2008 7:12:50 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/12/2008 4:29:48 PM
Posts: 2, Visits: 15
Hi Keithuk. I have seen helping a lot of people on this forum. First I want to thank you for your time.

I'm having trouble with checking the number from the textbox with the numbers in the arrays. I'm not really sure where to go from here.

Here is what I have so far:

Dim intAccounts(17) As Integer
Dim intCount As Integer

intAccounts(0) = 5658845
intAccounts(1) = 4520125
intAccounts(2) = 7895122
intAccounts(3) = 8777541
intAccounts(4) = 8451277
intAccounts(5) = 1302850
intAccounts(6) = 8080152
intAccounts(7) = 4562555
intAccounts(8) = 5552012
intAccounts(9) = 5050552
intAccounts(10) = 7825877
intAccounts(11) = 1250255
intAccounts(12) = 1005231
intAccounts(13) = 6545231
intAccounts(14) = 3852085
intAccounts(15) = 7576651
intAccounts(16) = 7881200
intAccounts(17) = 4581002

Post #24874
Posted 5/11/2008 12:23:18 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 11:08:46 PM
Posts: 348, Visits: 1,704
mike123 (5/10/2008)

I'm having trouble with checking the number from the textbox with the numbers in the arrays. I'm not really sure where to go from here.

Here is what I have so far:

Dim intAccounts(17) As Integer
Dim intCount As Integer

intAccounts(0) = 5658845
intAccounts(1) = 4520125
intAccounts(2) = 7895122

Mike, the first thing you need to do is change intAccounts(17) to a Long Integer, or you will get an Overflow error.

Option Explicit
Dim lngAccounts(17) As Long

Integers can only hold numerical values between -32,768 to 32,767. Secondly, if your instructor will permit you to use a ListBox along with your TextBox it will make searching for a value match very convenient. Once you have the array values in a ListBox you can search for a match with something like this partial code that goes in a For - Next Loop...

If (lngAccounts(i)) = Text1.Text Then
         List1.ListIndex = (i)
         MsgBox "A Match Has Been Found!"
End If

As Keith stated earlier, we will help with assignments but encourage the student to take the initiative to at least attempt to complete the code snippets themselves.

Good luck!

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #24876
Posted 5/11/2008 7:25:34 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 4:36:16 PM
Posts: 1,463, Visits: 3,400
Nicely put Chris.

Option Explicit

Dim lngAccounts(17) As Long

Private Sub Command1_Click()

Dim N As Integer
Dim Found As Boolean

'UBound finds the upper value of an array
For N = 0 To UBound(lngAccounts)
    If lngAccounts(N) = Val(Trim(Text1.Text)) Then
        MsgBox Text1.Text & " as been found!"
        Found = True
    End If
Next
If Found = False Then
    MsgBox Text1.Text & " as not been found!"
End If

End Sub

Private Sub Form_Load()

lngAccounts(0) = 5658845
lngAccounts(1) = 4520125
lngAccounts(2) = 7895122
lngAccounts(3) = 8777541
lngAccounts(4) = 8451277
lngAccounts(5) = 1302850
lngAccounts(6) = 8080152
lngAccounts(7) = 4562555
lngAccounts(8) = 5552012
lngAccounts(9) = 5050552
lngAccounts(10) = 7825877
lngAccounts(11) = 1250255
lngAccounts(12) = 1005231
lngAccounts(13) = 6545231
lngAccounts(14) = 3852085
lngAccounts(15) = 7576651
lngAccounts(16) = 7881200
lngAccounts(17) = 4581002

End Sub



Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #24877
Posted 5/11/2008 9:42:00 AM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 4:38:01 AM
Posts: 886, Visits: 5,287
This is pretty close to what Keith had suggested.

Private Sub Command1_Click()
Dim UB As Integer
Dim N As Integer

    'UBound finds the upper value of an array
    UB = UBound(lngAccounts)
    
    'Loop through the array and see if there is a match.
    For N = 0 To UB
        If lngAccounts(N) = Val(Trim(Text1.Text)) Then
            'exit the loop if the item was found
            Exit For
        End If
    Next
    
    'If the loop counter is greater than the UBound of the array the
    'item was not found in the array.
    If N > UB Then
        MsgBox Text1.Text & " was not been found!"
    Else
        MsgBox Text1.Text & " was found at index position " & N
    End If
    
End Sub
Post #24878
Posted 5/11/2008 10:27:21 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 11:08:46 PM
Posts: 348, Visits: 1,704
Mark (5/11/2008)
This is pretty close to what Keith had suggested.

Mark, I'm glad you posted this. In my code (using a ListBox) I didn't include a MsgBox in the event of a match not found. After I posted that code I added it to my project using a Bln flag, much the same way that Keith did in his code. Eliminating the flag is a plus though.  

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #24879
Posted 5/12/2008 11:37:29 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 11:08:46 PM
Posts: 348, Visits: 1,704
Mike, you may want to add this as the first command in the command1.Click event. It will eliminate odd looking MsgBox messages.
If Text1.Text = "" Then
      MsgBox "You did not enter anything!"
      Exit Sub
End If


 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #24895
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Brian, Peter

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 7:56am