Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help With Multiplication In Visual Basic?
New Posts  All Forums:Forum Nav:

Help With Multiplication In Visual Basic? - Page 2

post #11 of 37
Thread Starter 
Quote:
Originally Posted by 3930K View Post

Sure!
Code:
Private Sub IncomeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncomeButton.Click
Basically tell the compiler exactly what it does.
Code:
' Write the code to multiply the sales by the prices to find the income
        Dim row As Integer
        Dim column As Integer
Set the local variables.
Code:
For row = 0 To 4
Takes row and increments it every time it goes to next, for example if you put MsgBox(row) it would show 0, 1, 2, 3 and finally 4.
Code:
For column = 0 To 2
Same deal with column.
Code:
income(row) = income(row) + (sales(row, column) * prices(column))
Income (the array)'s row is equal to itself plus the sales (row and column) times the prices by the column.
Code:
    Next
Next
Go to the next iteration.
Code:
DisplayIncome()
Display it.
Code:
End Sub
End the sub.

Nice one, this is what I thought. Good to see I had the right idea.
Thank you so much mate! if you need anything, do let me know smile.gif
Thanks man!
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #12 of 37
Quote:
Originally Posted by dushan24 View Post

Forgot how weird loops are in VB, why does the language require a "next" to make the loop increment...

Java/PHP/C# syntax makes a lot more sense.

for(something; to something; increment operator)
{
//Do something
}
It's a different style. I personally don't like that you have to use Dim in basic, but it's the language.

The equivalent in vb:
'Something
for something = 0 to (someint) step (how much to increment by)
'do something
next
post #13 of 37
Thread Starter 
Quote:
Originally Posted by 3930K View Post

It's a different style. I personally don't like that you have to use Dim in basic, but it's the language.

The equivalent in vb:
'Something
for something = 0 to (someint) step (how much to increment by)
'do something
next

I don't mind using DIM, as it allows me to use personal and memorable names to assign things to/with.
If I want to add two numbers, I can use dim addnumbers as integer. Or I can just use that as a local variable for a certain sub precedure.
I'm just use to it I guess.
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #14 of 37
Whoops, found another bug.

http://pastebin.com/9inSaegF
post #15 of 37
Quote:
Originally Posted by dushan24 View Post

Forgot how weird loops are in VB, why does the language require a "next" to make the loop increment...

Java/PHP/C# syntax makes a lot more sense.

for(something; to something; increment operator)
{
//Do something
}

It's just syntax.. the "Next" is just like the closing bracket in your example. Technically, you don't even need to put anything in a for statement (it's just like doing while(true)). I agree though, I much prefer the C style syntax over the wordy VB style haha.. but that's only because I've been at it for quite a while. When I first started out I think starting with VB made it a bit easier to get into, maybe rolleyes.gif
Code:
for ( ; ; )
    Console.WriteLine("Hello, World!");
post #16 of 37
Code:
do
{
    //crash
}
while(1 = 1);

Haha :-)
    
CPUMotherboardGraphicsGraphics
Intel Core i7 860 Asus P7P55D-E Pro MSI GTX560 Ti TwinFrozr II MSI GTX560 Ti TwinFrozr II 
RAMHard DriveHard DriveHard Drive
Corsair 8GB DDR3 OCZ Vertex 3 Western Digital Caviar Black Western Digital Caviar Green 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro Lite-On 24x DVD-RW CoolerMaster V8 Windows 8.1 Professional 
OSMonitorMonitorMonitor
Debian 7.1 Samsung S22B350H Samsung S22B350H Samsung S22B350H 
KeyboardPowerCaseMouse
Ducky Shine II Corsair HX850 CoolerMaster Storm Enforcer Logitech M500 
Mouse PadAudio
Razer Goliathus Microsoft LifeChat LX 3000 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Intel Core i7 860 Asus P7P55D-E Pro MSI GTX560 Ti TwinFrozr II MSI GTX560 Ti TwinFrozr II 
RAMHard DriveHard DriveHard Drive
Corsair 8GB DDR3 OCZ Vertex 3 Western Digital Caviar Black Western Digital Caviar Green 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro Lite-On 24x DVD-RW CoolerMaster V8 Windows 8.1 Professional 
OSMonitorMonitorMonitor
Debian 7.1 Samsung S22B350H Samsung S22B350H Samsung S22B350H 
KeyboardPowerCaseMouse
Ducky Shine II Corsair HX850 CoolerMaster Storm Enforcer Logitech M500 
Mouse PadAudio
Razer Goliathus Microsoft LifeChat LX 3000 
  hide details  
Reply
post #17 of 37
Quote:
Originally Posted by cipp View Post

It's just syntax.. the "Next" is just like the closing bracket in your example. Technically, you don't even need to put anything in a for statement (it's just like doing while(true)). I agree though, I much prefer the C style syntax over the wordy VB style haha.. but that's only because I've been at it for quite a while. When I first started out I think starting with VB made it a bit easier to get into, maybe rolleyes.gif
Code:
for ( ; ; )
    Console.WriteLine("Hello, World!");

You don't need to include the braces, I just do so because I like good syntax

IE: This would work in Java
Code:
for(int i = 0; i < 5; i++)
    System.out.println("Hi");

As would this
Code:
if(1 = 1)
    System.out.print("Cool");
    
CPUMotherboardGraphicsGraphics
Intel Core i7 860 Asus P7P55D-E Pro MSI GTX560 Ti TwinFrozr II MSI GTX560 Ti TwinFrozr II 
RAMHard DriveHard DriveHard Drive
Corsair 8GB DDR3 OCZ Vertex 3 Western Digital Caviar Black Western Digital Caviar Green 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro Lite-On 24x DVD-RW CoolerMaster V8 Windows 8.1 Professional 
OSMonitorMonitorMonitor
Debian 7.1 Samsung S22B350H Samsung S22B350H Samsung S22B350H 
KeyboardPowerCaseMouse
Ducky Shine II Corsair HX850 CoolerMaster Storm Enforcer Logitech M500 
Mouse PadAudio
Razer Goliathus Microsoft LifeChat LX 3000 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Intel Core i7 860 Asus P7P55D-E Pro MSI GTX560 Ti TwinFrozr II MSI GTX560 Ti TwinFrozr II 
RAMHard DriveHard DriveHard Drive
Corsair 8GB DDR3 OCZ Vertex 3 Western Digital Caviar Black Western Digital Caviar Green 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro Lite-On 24x DVD-RW CoolerMaster V8 Windows 8.1 Professional 
OSMonitorMonitorMonitor
Debian 7.1 Samsung S22B350H Samsung S22B350H Samsung S22B350H 
KeyboardPowerCaseMouse
Ducky Shine II Corsair HX850 CoolerMaster Storm Enforcer Logitech M500 
Mouse PadAudio
Razer Goliathus Microsoft LifeChat LX 3000 
  hide details  
Reply
post #18 of 37
Quote:
Originally Posted by dushan24 View Post

Code:
do
{
    //crash
}
while(1 = 1);
You're better off just doing
Code:
while (True);

Quote:
Originally Posted by dushan24 View Post

You don't need to include the braces, I just do so because I like good syntax

IE: This would work in Java
Code:
for(int i = 0; i < 5; i++)
    System.out.println("Hi");

As would this
Code:
if(1 = 1)
    System.out.print("Cool");

That's different because those are single line conditionals and iterations. Multi-line iterations do require braces.

For the record, VB supports single line conditionals as well:
Code:
If 1=1 Then Console.WriteLine "Cool"
You'll notice that the VB code there is also more compact than your Java code.

Also, while I'm inspecting your code, you made an error:
Code:
if(1 = 1)
You're assigning 1 rather than checking its equivalence. You also did the same in your do loop in the previous post. smile.gif
post #19 of 37
Quote:
Originally Posted by 3930K View Post

It's a different style. I personally don't like that you have to use Dim in basic, but it's the language.

The equivalent in vb:
'Something
for something = 0 to (someint) step (how much to increment by)
'do something
next

Quote:
Originally Posted by BradleyW View Post

I don't mind using DIM, as it allows me to use personal and memorable names to assign things to/with.
If I want to add two numbers, I can use dim addnumbers as integer. Or I can just use that as a local variable for a certain sub precedure.
I'm just use to it I guess.

I suspect you two are discussing different things (or at least I hope you are as you should always declare your variables (this is one of my biggest criticisms of PHP).

With VB (as with a Perl), you don't have to declare your variables, but it's good practice to. Option Explicit will enable a compile time flag forcing errors if data is assigned to an undeclared variable.
post #20 of 37
Quote:
Originally Posted by dushan24 View Post

Code:
do
{
    //crash
}
while(1 = 1);

Haha :-)
That's assigning to a constant, no no.

^ No, i just don't like that you have to type Dim (somevarname) As Integer : (somevarname) = (somefunc) vs int (somevarname) = (somefunction)
Edited by 3930K - 1/21/13 at 7:07am
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help With Multiplication In Visual Basic?