SimpleVB Coding problem

Discussion in 'OT Technology' started by Chromey, May 14, 2005.

  1. Chromey

    Chromey OT Supporter

    Joined:
    Aug 8, 2003
    Messages:
    1,036
    Likes Received:
    0
    Location:
    Melbourne, Australia
    THis is shitting me up the wall, anyone have any hintsas towhat is wrong with my code?





    Option Strict On

    Option Explicit On



    Public Class Form1

    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 btnAnalyze As System.Windows.Forms.Button

    Friend WithEvents lbx1 As System.Windows.Forms.ListBox

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    Me.btnAnalyze = New System.Windows.Forms.Button

    Me.lbx1 = New System.Windows.Forms.ListBox

    Me.SuspendLayout()

    '

    'btnAnalyze

    '

    Me.btnAnalyze.Location = New System.Drawing.Point(152, 336)

    Me.btnAnalyze.Name = "btnAnalyze"

    Me.btnAnalyze.TabIndex = 1

    Me.btnAnalyze.Text = "Analyze"

    '

    'lbx1

    '

    Me.lbx1.Location = New System.Drawing.Point(16, 8)

    Me.lbx1.Name = "lbx1"

    Me.lbx1.Size = New System.Drawing.Size(712, 316)

    Me.lbx1.TabIndex = 3

    '

    'Form1

    '

    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

    Me.ClientSize = New System.Drawing.Size(784, 366)

    Me.Controls.Add(Me.lbx1)

    Me.Controls.Add(Me.btnAnalyze)

    Me.Name = "Form1"

    Me.Text = "Form1"

    Me.ResumeLayout(False)



    End Sub



    #End Region



    Private Sub Analyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyze.Click

    'declare the variables

    Dim sreCompany As IO.StreamReader

    Dim sredivide1 As IO.StreamReader

    Dim sredivide2 As IO.StreamReader



    Dim fmtStr As String = "{0,5} {1,10} {2,5} {3,10} {4,5} {5,5}"

    Dim strCode As String

    Dim strCompany As String

    Dim strOwner As String

    Dim strTaxed As String

    Dim sngReceived As Single

    Dim sngAftertax As Single

    Dim strOutput As String



    Dim strAmount As String

    Dim strdividend As String









    'read the records in the text files

    If IO.File.Exists("companies.txt") Then

    sreCompany = IO.File.OpenText("companies.txt")

    Do While (Not sreCompany.Peek() = -1)

    strOwner = sreCompany.ReadLine

    strCode = sreCompany.ReadLine

    strCompany = sreCompany.ReadLine

    If strOwner = "1" Then

    strOwner = "Mr."

    Else

    strOwner = "Mrs."

    End If

    Loop

    sreCompany.Close()

    Else

    MessageBox.Show("'companies.txt' not found")

    End If



    If IO.File.Exists("dividends1.txt") Then

    sredivide1 = IO.File.OpenText("dividends1.txt")

    strOwner = "Mr."

    Do While (Not sredivide1.Peek() = -1)

    strCode = sredivide1.ReadLine

    strAmount = sredivide1.ReadLine

    strdividend = sredivide1.ReadLine

    strTaxed = sredivide1.ReadLine

    sngReceived = (Convert.ToSingle(strAmount) * Convert.ToSingle(strdividend))

    If strTaxed = "N" Then

    strTaxed = "No"

    sngAftertax = sngReceived * (Convert.ToSingle(0.78))

    Else

    strTaxed = "Yes"

    sngAftertax = sngReceived

    End If

    Loop

    sredivide1.Close()

    Else

    MessageBox.Show("'dividends1.txt' not found")

    End If





    If IO.File.Exists("dividends2.txt") Then

    sredivide1 = IO.File.OpenText("dividends2.txt")

    strOwner = "Mrs."

    Do While (Not sredivide2.Peek() = -1)

    strCode = sredivide2.ReadLine

    strAmount = sredivide2.ReadLine

    strdividend = sredivide2.ReadLine

    strTaxed = sredivide2.ReadLine

    sngReceived = (Convert.ToSingle(strAmount) * Convert.ToSingle(strdividend))

    If strTaxed = "N" Then

    strTaxed = "No"

    sngAftertax = sngReceived * (Convert.ToSingle(0.78))

    Else

    strTaxed = "Yes"

    sngAftertax = sngReceived

    End If

    Loop

    sredivide2.Close()

    Else

    MessageBox.Show("'dividends2.txt' not found")

    End If







    ' Use the format string above to format name, age and phone number

    strOutput = String.Format(fmtStr, strCode, strCompany, strOwner, sngReceived, strTaxed)



    lbx1.Items.Add(strOutput)







    End Sub



    Private Sub lbx1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub



    Private Sub lbx1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub



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



    End Sub

    [font=&quot]End Class[/font]
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I think I know what is wrong. YOU'RE CODING IN VISUAL BASIC. Get some fucking self respect, learn a real language and then get back to us.

    Okay, that wasn't helpful. But to be honest, the code you pasted is so crappy, noone is going to debug it for you. Maybe you should link to a text file?
     
  3. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :werd: When posting code to be debugged, it is very important to:

    a) Post it in [ php ] tags so that the indentation is preserved and your code is reasable.
    b) Tell us what the problem you're having is, no one is going to look through all those lines of code and try and find an unspecified problem.
     
  4. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Better yet, just link us to a text file that is properly indented. Or do you even indent in VB? Are you using a debugger? Or even something as primitive as alot of printfs?
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    IIRC VB mandates indentation and doesn't work if it's not indented properly.

    Edit: And there's a builtin debugger, which doesn't mean he's using it, but he could be.
     

Share This Page