|
-
Oct 29th, 2010, 08:55 AM
#1
Thread Starter
New Member
module multiplication loop
Hi I'm new to VB an i'm trying to make a multiplication and sum table only form 1 to 12. I get all kind of error I don't know what to do, help please?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim numMulti, numSum, tCounter, multiSum As Integer
tCounter = 0
\\number enter by user
numMulti = CDbl(TextBox1.Text)
numSum = CDbl(TextBox1.Text)
\\module call statement
Call multiSuma(byval tablaMulti, tablaSuma as integer)
\\list box where the result will be display
ListBox1 = CStr(tMulti)
ListBox2 = CStr(tSum)
End Sub
End Class
\\start module
Sub multiSuma(ByRef tCounter, ByVal numMulti, ByVal numSum As Integer)
\\variable to save the data of te sum and multiplication
Dim tSum, tMulti As Integer
\\start loop with a counter
Do Until tCounter = 12
tMulti = tCounter * numMulti
tSum = tCounter + numSum
tCounter = tCounter + 1
Loop
End Sub
-
Oct 29th, 2010, 08:58 AM
#2
Re: module multiplication loop
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
-
Oct 29th, 2010, 09:03 AM
#3
Re: module multiplication loop
I see the first error. You have declared the sub MultiSuma to take three arguments: tCounter, tablaMulti, and tablaSuma, but when you call the method you are passing in only two arguments. Based on the names you are using, it appears that you are not giving MultiSuma the tCounter argument that it is expecting.
Another error is that you declare the variables tMulti and tSum inside the MultiSuma method, yet you attempt to display them outside of the method. That won't work. Since the variables are declared inside the method, they can't be seen by any code outside of that method. The solution would be to declare tMulti and tSum at form scope, outside of any method. Otherwise, you would have to pass them back out of the method, which is somewhat more involved.
My usual boring signature: Nothing
 
-
Oct 29th, 2010, 10:30 AM
#4
Thread Starter
New Member
Re: module multiplication loop
This program are suppous to creat a multiplication table
the program will tell the user to entera a number and it will display the result in a listbox, I by far have created the code but the list box don't display the list of multiplication, it has to display if I enter number 1 the multiplication 1x1 =1, 1x2=2, 1x3=3, please help, write the code if possible.
Dim numeroMulti, numeroSuma, tCounter, tMulti, tSuma As Integer
tCounter = 0
'data enter by the user
numeroMulti = CDbl(TextBox1.Text)
numeroSuma = CDbl(TextBox1.Text)
'start loop do until
Do Until tCounter = 12
tMulti = tCounter * numeroMulti
tSuma = tCounter + numeroSuma
tCounter = tCounter + 1
Loop
'list box where the result will be displa
ListBox1.Items.Add(tCounter)
ListBox2.Items.Add(tSuma)
End Sub
-
Oct 29th, 2010, 12:03 PM
#5
Re: module multiplication loop
You are adding tCounter to the listbox rather than tMulti.
My usual boring signature: Nothing
 
-
Oct 29th, 2010, 03:07 PM
#6
Thread Starter
New Member
Re: module multiplication loop
My program is running great with one little problem it keep adding a cero to my listbox and the multiplication and sum result don't line up well. Heeeeelp. the result would be like:
1X0 = 0 <==== The Problem 
1X1 = 0
1X2 = 1
1X3 = 2
===============new code===============================
Dim numeroMulti, numeroSuma As Integer
'data enter by user
numeroMulti = CDbl(TextBox1.Text)
numeroSuma = CDbl(TextBox1.Text)
'line of code to call modulo tmultiSuma
Call tmultiSuma(numeroMulti, numeroSuma)
End Sub
'start modul tmultiSuma
Public Sub tmultiSuma(ByVal numeroMulti As Integer, ByVal numeroSuma As Integer)
Dim tMulti, tSuma, tCounter As Integer
'loop to calculat sum and multiplication table
Do Until tCounter = 13
'lista resultado multiplicacion
ListBox1.Items.Add(tCounter & "X" & numeroMulti & "=" & "" & tMulti)
'lista resultado suma
ListBox2.Items.Add(tCounter & "+" & numeroSuma & "=" & "" & tSuma)
'operation with a counter
tMulti = tCounter * numeroMulti
tSuma = tCounter + numeroSuma
tCounter = tCounter + 1
Loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|