CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Exclamation *Urgent* Help with VB Code

    I procrastinate like you would believe! I have this homework project due tomorrow and I keep getting errors specifically with "index" do I have to declare it somewhere or add a specific item form the Toolbox on my form? I'm stuck help!!

    Code:
    Public Class Form1
    Dim Wname(10) As String
    Dim Hours(10) As Integer
    Dim Wages(10) As Integer
    Dim Wpay(10) As Integer Private index As Integer = 0
    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim nind As Integer = 0
    Dim ind, total As Integer
    Dim fmtStr As String = "{0,-10} {1,20}"
    
    For ind = 0 To index
    total += Wpay(ind)
    Next
      lstSummary.Items.Add(String.Format(fmtStr, "Worker Name", "Payment"))
    For nind = 0 To index - 1
      lstSummary.Items.Add(String.Format(fmtStr, Wname(nind), Wpay(nind)))
    Next
      lstSummary.Items.Add("Total Workers Processed :" & index)
      lstSummary.Items.Add("Total Wages Payed :" & total)
    End Sub
    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
    Wname(index) = txtName.Text
    Hours(index) = CInt(txtHours.Text)
    Wages(index) = CInt(txtWage.Text)
    If Hours(index) > 40 Then
    Wpay(index) = 1.5 * Wages(index) * Hours(index)
    Else Wpay(index) = Hours(index) * Wages(index)
    End If
      index += 1
      txtName.Clear()
      txtHours.Clear()
      txtWage.Clear()
      txtName.Focus()
    End Sub
    End Class

  2. #2
    Join Date
    Aug 2011
    Posts
    3

    Re: *Urgent* Help with VB Code

    Sorry forgot to post the Program question>

    The Program:

    Design a VB.Net project to compute the weekly pay of the workers in a factory.Assume that each worker is paid the regular hourly pay if he/she works 40 hours or less in a week.For additional hours beyond 40, the worker should be paid overtime, which is 1.5 times the regular hourly pay. Allow the user to enter the worker's name, hours worked, and hourly wage on the Form, and click on a Button to get the workers pay displayed in the output box with a descriptive message that includes the name of the worker. The program should also display the number of workers processed and total wages paid.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: *Urgent* Help with VB Code

    Code:
    Dim Wpay(10) As Integer Private index As Integer = 0
    You can not do declarations like this.

    you need a new line for the next definition.. like

    Code:
    Dim Wpay(10) As Integer 
    Private index As Integer = 0
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Aug 2011
    Posts
    3

    Re: *Urgent* Help with VB Code

    Oh my Gosh, was that all!!?? I hate it when I go crazy trying to find out what is wrong and it is just that simple like in C++ when it is just a semicolon missing. Thank you so much, it now works great.

  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: *Urgent* Help with VB Code

    Design a VB.Net project to compute the weekly pay of the workers in a factory.
    [...]
    Was the declaration all? Depends. As it is a homework, it might be enough if you do not plan to dig more under the hood of IT science. As it seems as if you're a student, it might worth the time to think if there could be a different way to do the same job.

    Before reading more, keep in mind your teacher could be really satisfied with a structured code like the one you posted: it is small, after all, and seems to do the job assigned, and the way you carried it out is quite sure good for the classrom.

    In our word, however, we can do things in many ways from simplest to dangerously complex. If you want another point of view, make a small search about OOP (Object Oriented Programming) and you might discover something.

    For example, you could have had a "List of Workers".
    each single "Worker" could have had a Name, a Weekly Worked Hours and a Base Salary (non necessarily equal to each others).
    The Object who holds the "List Of Workers" could also have had methods to calculate salary of each worker and applay the corrections required for extra or less job...

    Now, this would have lead apparently to more code, and of course to a bit more complex project. But it would have also made the project a bit more flexible and -who knows?-more desired after some times,when it always happens requirements change and you start work out of the school...

    TheOldTeacher
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: *Urgent* Help with VB Code

    In other words, it takes 10 times LESS the amount of lines of code to do the same thing, as opposed to 20 years ago, before OOP

    Suppose you're GM, and have to do 50,000 payrolls per day, for each DIVISION.

    http://channel9.msdn.com/Shows/Silve...ive-Extensions
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: *Urgent* Help with VB Code

    Mystic Rose, please do not mark your thread *Urgent*. All the threads you see in this forum is quite urgent

  8. #8
    Join Date
    Aug 2011
    Posts
    10

    Re: *Urgent* Help with VB Code

    hi, im using vb 2010 and currently working on a program that senses and displays values in "textbox1", however the values are in hex form, but i require them to be in decimal form
    ? for example 006d = 109. i want the value 109 to be displayed into the textbox instead of 006d..
    pplease help

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: *Urgent* Help with VB Code

    That makes two questions at the same time? Sounds like you want the answer, not how to figure it out. Start a new thread, but keep questions to one at a time.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: *Urgent* Help with VB Code

    Quote Originally Posted by nicholasang View Post
    hi, im using vb 2010 and currently working on a program that senses and displays values in "textbox1", however the values are in hex form, but i require them to be in decimal form
    ? for example 006d = 109. i want the value 109 to be displayed into the textbox instead of 006d..
    pplease help
    You should start a new thread when you have a new question but before you even ask the question you should do a search and see if you can find an answer.

    In this case the answer is simple.

    1: Open your web browser to Google or other search engine
    2: type into the search field hex to decimal vb.net
    3: check the resulting pages
    Always use [code][/code] tags when posting code.

  11. #11
    Join Date
    Aug 2011
    Posts
    10

    Re: *Urgent* Help with VB Code

    thats what i have been doing for the past few days, but cant find what am looking for, am really getting desperate as my deadline is approaching...

  12. #12
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: *Urgent* Help with VB Code

    Interesting I did the search and found at least 3 different ways to do it in the first 4 links.
    Always use [code][/code] tags when posting code.

  13. #13
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: *Urgent* Help with VB Code

    **EDIT**
    oppsss...did not see the poster followed the correct suggestion to starta new thread:
    http://www.codeguru.com/forum/showthread.php?t=515352
    *******
    We must help this one... here:
    http://stackoverflow.com/questions/6...l-using-vb-net

    and here: http://www.geekpedia.com/KB8_How-do-...o-decimal.html
    but as the latter is in c#, I translate it for you in a sample solution I attach here.
    Code is
    Code:
    Public Class Form1
        
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'a sample value to show you how your Hex shoudl be as a string 
            TextBox1.Text = 1521.ToString("X")
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim thevalue As Integer
            Dim numberstyle As System.Globalization.NumberStyles
            numberstyle = System.Globalization.NumberStyles.HexNumber
            Try
                thevalue = Integer.Parse(TextBox1.Text, numberstyle)
                TextBox2.Text = thevalue.ToString
            Catch
                MessageBox.Show("Sorry, could not convert " & TextBox1.Text & " to ""decimal"" integer")
            End Try
    
    
        End Sub
    
        
    End Class
    Attached Files Attached Files
    Last edited by Cimperiali; August 12th, 2011 at 03:13 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured