User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » VB Help for a friend... Page [1]  
Gozo
All American
10337 Posts
user info
edit post

Ok, my friend is almost failing his VB class. He sent me the code but all I have in the VB integrated into MSWord and everything is red. He has trouble with one of the loops and with the multiplication operator.

Ok, here's the code:

Option Strict On
Option Explicit On
Public Class uiClassPlacement
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents uiPositiveIntegerLabel As System.Windows.Forms.Label
Friend WithEvents uiSumLabel As System.Windows.Forms.Label
Friend WithEvents uiProductLabel As System.Windows.Forms.Label
Friend WithEvents uiOddEvenLabel As System.Windows.Forms.Label
Friend WithEvents uiIntegerAnswerTextBox As System.Windows.Forms.TextBox
Friend WithEvents uiGoButton As System.Windows.Forms.Button
Friend WithEvents uiClearButton As System.Windows.Forms.Button
Friend WithEvents uiExitButton As System.Windows.Forms.Button
Friend WithEvents uiTotalSumLabel As System.Windows.Forms.Label
Friend WithEvents uiTotalProductLabel As System.Windows.Forms.Label
Friend WithEvents uiOddEvenSumLabel As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.uiPositiveIntegerLabel = New System.Windows.Forms.Label
Me.uiSumLabel = New System.Windows.Forms.Label
Me.uiProductLabel = New System.Windows.Forms.Label
Me.uiOddEvenLabel = New System.Windows.Forms.Label
Me.uiIntegerAnswerTextBox = New System.Windows.Forms.TextBox
Me.uiGoButton = New System.Windows.Forms.Button
Me.uiClearButton = New System.Windows.Forms.Button
Me.uiExitButton = New System.Windows.Forms.Button
Me.uiTotalSumLabel = New System.Windows.Forms.Label
Me.uiTotalProductLabel = New System.Windows.Forms.Label
Me.uiOddEvenSumLabel = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'uiPositiveIntegerLabel
'
Me.uiPositiveIntegerLabel.Location = New System.Drawing.Point(8, 8)
Me.uiPositiveIntegerLabel.Name = "uiPositiveIntegerLabel"
Me.uiPositiveIntegerLabel.Size = New System.Drawing.Size(104, 24)
Me.uiPositiveIntegerLabel.TabIndex = 0
Me.uiPositiveIntegerLabel.Text = "Positive Integer"
'
'uiSumLabel
'
Me.uiSumLabel.Location = New System.Drawing.Point(8, 48)
Me.uiSumLabel.Name = "uiSumLabel"
Me.uiSumLabel.Size = New System.Drawing.Size(80, 24)
Me.uiSumLabel.TabIndex = 2
Me.uiSumLabel.Text = "Total Sum"
'
'uiProductLabel
'
Me.uiProductLabel.Location = New System.Drawing.Point(8, 96)
Me.uiProductLabel.Name = "uiProductLabel"
Me.uiProductLabel.Size = New System.Drawing.Size(80, 24)
Me.uiProductLabel.TabIndex = 4
Me.uiProductLabel.Text = "Total Product"
'
'uiOddEvenLabel
'
Me.uiOddEvenLabel.Location = New System.Drawing.Point(8, 136)
Me.uiOddEvenLabel.Name = "uiOddEvenLabel"
Me.uiOddEvenLabel.Size = New System.Drawing.Size(88, 24)
Me.uiOddEvenLabel.TabIndex = 6
Me.uiOddEvenLabel.Text = "Odd - Even Sum"
'
'uiIntegerAnswerTextBox
'
Me.uiIntegerAnswerTextBox.Location = New System.Drawing.Point(128, 8)
Me.uiIntegerAnswerTextBox.Name = "uiIntegerAnswerTextBox"
Me.uiIntegerAnswerTextBox.Size = New System.Drawing.Size(104, 20)
Me.uiIntegerAnswerTextBox.TabIndex = 1
Me.uiIntegerAnswerTextBox.Text = ""
'
'uiGoButton
'
Me.uiGoButton.Location = New System.Drawing.Point(40, 200)
Me.uiGoButton.Name = "uiGoButton"
Me.uiGoButton.Size = New System.Drawing.Size(72, 24)
Me.uiGoButton.TabIndex = 8
Me.uiGoButton.Text = "&Go"
Me.uiGoButton.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'uiClearButton
'
Me.uiClearButton.Location = New System.Drawing.Point(112, 200)
Me.uiClearButton.Name = "uiClearButton"
Me.uiClearButton.Size = New System.Drawing.Size(64, 24)
Me.uiClearButton.TabIndex = 9
Me.uiClearButton.Text = "&Clear"
'
'uiExitButton
'
Me.uiExitButton.Location = New System.Drawing.Point(176, 200)
Me.uiExitButton.Name = "uiExitButton"
Me.uiExitButton.Size = New System.Drawing.Size(56, 24)
Me.uiExitButton.TabIndex = 10
Me.uiExitButton.Text = "&Exit"
'
'uiTotalSumLabel
'
Me.uiTotalSumLabel.BackColor = System.Drawing.SystemColors.Control
Me.uiTotalSumLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.uiTotalSumLabel.Location = New System.Drawing.Point(104, 48)
Me.uiTotalSumLabel.Name = "uiTotalSumLabel"
Me.uiTotalSumLabel.Size = New System.Drawing.Size(80, 24)
Me.uiTotalSumLabel.TabIndex = 3
'
'uiTotalProductLabel
'
Me.uiTotalProductLabel.BackColor = System.Drawing.SystemColors.Control
Me.uiTotalProductLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.uiTotalProductLabel.Location = New System.Drawing.Point(104, 88)
Me.uiTotalProductLabel.Name = "uiTotalProductLabel"
Me.uiTotalProductLabel.Size = New System.Drawing.Size(80, 24)
Me.uiTotalProductLabel.TabIndex = 5
'
'uiOddEvenSumLabel
'
Me.uiOddEvenSumLabel.BackColor = System.Drawing.SystemColors.Control
Me.uiOddEvenSumLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.uiOddEvenSumLabel.Location = New System.Drawing.Point(104, 128)
Me.uiOddEvenSumLabel.Name = "uiOddEvenSumLabel"
Me.uiOddEvenSumLabel.Size = New System.Drawing.Size(88, 24)
Me.uiOddEvenSumLabel.TabIndex = 7
'
'uiClassPlacement
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.uiOddEvenSumLabel)
Me.Controls.Add(Me.uiTotalProductLabel)
Me.Controls.Add(Me.uiTotalSumLabel)
Me.Controls.Add(Me.uiExitButton)
Me.Controls.Add(Me.uiClearButton)
Me.Controls.Add(Me.uiGoButton)
Me.Controls.Add(Me.uiIntegerAnswerTextBox)
Me.Controls.Add(Me.uiOddEvenLabel)
Me.Controls.Add(Me.uiProductLabel)
Me.Controls.Add(Me.uiSumLabel)
Me.Controls.Add(Me.uiPositiveIntegerLabel)
Me.Name = "uiClassPlacement"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiExitButton.Click
Me.Close()
End Sub
Private Sub OddEvenSumLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiOddEvenSumLabel.Click
End Sub
Private Sub uiClassPlacement_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub uiClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiClearButton.Click

Me.uiIntegerAnswerTextBox.Text = ""
Me.uiOddEvenSumLabel.Text = ""
Me.uiTotalProductLabel.Text = ""
Me.uiTotalSumLabel.Text = ""
'set the focus
Me.uiIntegerAnswerTextBox.Focus()


End Sub
Private Sub uiGoButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiGoButton.Click
Dim num1 As Integer
Dim num2 As Integer
Dim totalsum As Integer
Dim product As Integer
Dim oddeven As Integer
Dim start As Integer
start = Integer.Parse(uiIntegerAnswerTextBox.Text)
num1 = Integer.Parse(uiIntegerAnswerTextBox.Text)
num2 = Integer.Parse(uiIntegerAnswerTextBox.Text)
Do Until num1 = 0
num1 = num1 - 1
num2 = num1 + num2
Loop
totalsum = num2
Me.uiTotalSumLabel.Text = Convert.ToString(totalsum)
Do
Loop Until num1 <> 0
Do Until num1 = 0
num1 = num1 - 1
num2 = num1 * num2
Loop
product = num2
Me.uiTotalProductLabel.Text = Convert.ToString(product)





















End Sub
Private Sub uiClassPlacement_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'verify that the user wants to exit the application
Dim button As Integer
button = MessageBox.Show("Do you want to exit?", "Class Placement", _
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1)
'if the user selects the No button, don't close the form
If button = DialogResult.No Then
e.Cancel = True
End If
End Sub
End Class


--------------------------------------------------------------------------------
Reply here or PM me if you can help, thanks.

3/14/2006 9:26:57 PM

HaLo
All American
14276 Posts
user info
edit post

pretty sure VBA (what's included with word) ain't gonna run that

3/14/2006 9:32:00 PM

TheTabbyCat
All American
4428 Posts
user info
edit post

yeah, so it seems...im gonna get his version tomorrow

<--- Gozo

[Edited on March 14, 2006 at 10:06 PM. Reason : asdf]

3/14/2006 10:02:02 PM

Shaggy
All American
17820 Posts
user info
edit post

friends dont let friends program in VB

3/14/2006 11:07:33 PM

pmc
Veteran
372 Posts
user info
edit post

Tabs would be nice. All right, this is the only part of the code that seems to be logic-related.


Private Sub uiGoButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiGoButton.Click

Dim num1 As Integer
Dim num2 As Integer
Dim totalsum As Integer
Dim product As Integer
Dim oddeven As Integer
Dim start As Integer

start = Integer.Parse(uiIntegerAnswerTextBox.Text)
num1 = Integer.Parse(uiIntegerAnswerTextBox.Text)
num2 = Integer.Parse(uiIntegerAnswerTextBox.Text)

Do Until num1 = 0
num1 = num1 - 1
num2 = num1 + num2
Loop

totalsum = num2
Me.uiTotalSumLabel.Text = Convert.ToString(totalsum)

Do
Loop Until num1 <> 0

Do Until num1 = 0
num1 = num1 - 1
num2 = num1 * num2
Loop

product = num2
Me.uiTotalProductLabel.Text = Convert.ToString(product)

End Sub


What... um... what exactly is the problem?

{edit}

By which, I mean, what is the code trying to accomplish? Because currently it looks like it's going to get stuck in an infinite loop.

[Edited on March 14, 2006 at 11:36 PM. Reason : Clarification]

3/14/2006 11:33:24 PM

Incognegro
Suspended
4172 Posts
user info
edit post

well, if your friend can't write VB, your friend probably should fail your friend's VB class

3/15/2006 3:50:41 AM

mattc
All American
1172 Posts
user info
edit post

ugh vb is a horrible language to write in

why do people still use this

3/15/2006 1:42:24 PM

Gozo
All American
10337 Posts
user info
edit post

The old code is supposed to add the integer the user inputs to every number less to zero. (20 + 19 +18 + 17...). The new code is supposed to multiply using the same method. I asked him about the loop thing but he said it wasn't an issue, but VB froze when he ran. No, I know I'm not good at VB, only took a semester in high school. What is everyone's issue with VB?

3/15/2006 8:57:56 PM

mattc
All American
1172 Posts
user info
edit post

^

vb not a c-derived language,
no type-checking at compile time?
true = -1 (yes i understand why this happens, but it shouldn't)
oh and vb is not a c-derived language
before vb.net vb couldn't handle threads
no inheritance (before vb.net)


i hate it and i hate having to work with a website someone decided to code in vb.net


it is an ass of a language. like fortran.

3/16/2006 3:58:02 AM

Wolfmarsh
What?
5975 Posts
user info
edit post

The problem is his infinite loop.


Do
Loop Until num1 <> 0




Because like 5 lines above, he makes sure num1 = 0.

3/16/2006 8:06:39 AM

 Message Boards » Tech Talk » VB Help for a friend... Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.