Results 1 to 7 of 7

Thread: your all programmers right? for the love of god i need some help with this code!!!

  
  1. #1

    Exclamation your all programmers right? for the love of god i need some help with this code!!!

    The part with "#" above and below just wont work!? it just keeps saying:

    "nullreference exception was handled
    Object variable or With block variable not set."

    someone please help this is my coursework for computing for wednesday

    Also this is written with visual basic express.net 2010 btw.

    Code:
    Public Class Form1
        Dim fname, sname, fletter_name, fletter_sname, random_let As String
        Dim random_num As Integer
        Dim refcode As Object
        Dim counts As Integer
        Dim minimum As Integer
        Dim position As Integer
        Dim item_num As Integer
        Dim list(4) As Object
        Dim counter As Integer
      
     
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            fname = InputBox("please enter first name")
            sname = InputBox("please enter second name")
            TextBox1.Text = fname
            TextBox2.Text = sname
            Call extracting_letters(fletter_name, fletter_sname)
    
            Call random_generator(random_num, random_let)
            TextBox3.Text = fletter_name & fletter_sname & random_num & random_let
            Call queries(list, item_num, minimum)
        End Sub
    
    
        Private Sub extracting_letters(ByRef fname As String, ByRef sname As String)
            'picks out first letter from both first and second name.
            fletter_name = TextBox1.Text.Substring(0, 1)
            fletter_sname = TextBox2.Text.Substring(0, 1)
    
        End Sub
        Private Sub random_generator(ByRef random_num As Integer, ByRef random_let As String)
    
            'generate random number.
            Dim number As Integer
            Randomize()
            random_num = number
            number = Int(Rnd() * 10) + 1
            'generate random letter.
            random_let = Chr(Asc("a") + Int(26 * Rnd()))
    
        End Sub
        Private Sub queries(ByRef list, ByRef item_num, ByRef minimum)
            Dim choice As Integer
            Do
                MsgBox("welcome to the graphics card slection screen")
                choice = InputBox("Pease select an option to find:" & vbNewLine & "1 The fastest clock speed" & vbNewLine & "2 The most powerful processor" & vbNewLine & "3 The lowest storage for the highest cost" & vbNewLine & "4 Or end and display")
                If choice = 1 Then
                    Call graphics_speeds(item_num, list(4), minimum)
                End If
            Loop Until choice = 4
    
        End Sub
    
        Private Sub graphics_speeds(ByRef item_num, ByRef list(), ByRef minimum)
    
            Call setup(minimum, item_num, list) 'sets up list.
            Call get_minimum(minimum)             ' gets users input for number to search.
            Call Find_minimum(minimum, item_num, list)  ' counts the number of times users target number appears in the list.
        End Sub
        Private Sub setup(ByRef minimum, ByRef item_num, ByRef list)
            'sets all values to zero.
            minimum = 0
            item_num = 0
    
            lstspeeds.Items.Clear() 'clears list.
    
            lstspeeds.Items.Add(1986)
            lstspeeds.Items.Add(550)
            lstspeeds.Items.Add(870)
            lstspeeds.Items.Add(790)
            lstspeeds.Items.Add(1600) 'fill list with array.
    ###############################################      
      Do
                list(item_num) = Val(lstspeeds.Items(item_num))
    ###############################################
                item_num = item_num + 1
            Loop Until item_num = lstspeeds.Items.Count 'what do you say to make the program racognise how many items it has to go through?
    
        End Sub
    
        Private Sub get_minimum(ByRef minimum)
            minimum = InputBox("Enter the number you would like to count") 'asking for number to be counted.
        End Sub
        Private Sub Find_minimum(ByRef minimum, ByRef item_num, ByRef list())
            Dim position As Integer
            Dim counts As Integer
            counts = 0 'sets number of counts to 0
    
            For position = 0 To item_num - 1  'sets sets position of counter to 0.
                If list(position) > minimum Then
                    counts = counts + 1 'if the counter meets a number in the list that matches target the counts increase by 1.
                End If
            Next
            MsgBox("There were " & (counts) & " graphics cards which have a faster clock speed")
    
        End Sub
    End class
    Last edited by dotted; April 18th, 2011 at 20:42.

  2. #2
    Elite Dragon Mothrayas's Avatar
    Join Date
    Nov 2009
    Location
    The Netherlands
    Posts
    1,635

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Quote Originally Posted by dangleberries View Post
    your all programmers right?
    To answer that question, no.

    I wonder where you got that idea from.



    As for the problem, I'm sorry but I can't help you, because I don't know BASIC.

    The Awakening


  3. #3

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Quote Originally Posted by Mothrayas View Post
    To answer that question, no.

    I wonder where you got that idea from.

    .
    well surly theres some programmers on your team making wfto??

    and basically im just asking round different forums.

  4. #4

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Your variable 'list' is null. In the subroutine 'queries' it still holds a list (of 5 nulls), you pass list(4) to 'graphics_speed' so the variable 'list' there contains a null (it's also probably not a list anymore), which you pass to 'setup' and then try to access.

    Learn to use the debugger. It can tell you the values of your variables at runtime. Very useful.

  5. #5

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Thanks, ill have another attempt at fixing it taking both of your sets of advice into account.

    ---------- Post added at 17:48 ---------- Previous post was at 17:42 ----------

    Quote Originally Posted by verhoevenv View Post
    Your variable 'list' is null. In the subroutine 'queries' it still holds a list (of 5 nulls), you pass list(4) to 'graphics_speed' so the variable 'list' there contains a null (it's also probably not a list anymore), which you pass to 'setup' and then try to access.

    Learn to use the debugger. It can tell you the values of your variables at runtime. Very useful.
    i love you. works perfectly cheers i didnt notice that!
    Last edited by dangleberries; April 18th, 2011 at 17:47.

  6. #6
    Fly Ogre's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    96
    Gamer IDs

    Gamertag: Oggrr

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Quote Originally Posted by dangleberries View Post
    i love you. works perfectly cheers i didnt notice that!
    Sometimes you can't see the error until someone elses sees it Good for you!

  7. #7

    Default Re: your all programmers right? for the love of god i need some help with this code!!

    Quote Originally Posted by Ogre View Post
    Sometimes you can't see the error until someone elses sees it Good for you!
    very true, and very happy now i can hand in my course work!

Similar Threads

  1. Things I'd love to see changed in KeeperFX
    By DragonsLover in forum KeeperFX
    Replies: 9
    Last Post: February 24th, 2011, 09:26
  2. The current code
    By Dinberg in forum War for the Overworld
    Replies: 4
    Last Post: January 31st, 2011, 12:40
  3. HTML code help
    By Zander353 in forum Off Topic
    Replies: 9
    Last Post: October 22nd, 2010, 13:00
  4. Programmers wanted.
    By Mentor in forum War for the Overworld
    Replies: 0
    Last Post: October 11th, 2010, 21:40

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
  •