Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Another little problem!!


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2004, 02:21 PM
Confused II Confused II is offline
Newcomer
 
Join Date: Apr 2004
Posts: 13
Question Another little problem!!


Hi!
Back again with another little problem!! The following bit of my programme asks the user for a name of the machine and number of items produced to update the corresponding 'number in stock' value. It all seems to working except it doesn't update the number value!! Once again I'll just say I'm new to programming and it's getting late so it's probably something really stupid!! Anyway, I'd appreciate any help!

Code:
Sub Add_Stock()

'Button 4- This adds new stock on to the database when new items are manufactured

'Read Data

For i = 1 To 100
    machine(i) = Cells(i + 6, 3).Value
Next i

For i = 1 To 100
    availability(i) = Cells(i + 6, 5).Value
Next i

'Ask user for the name of the machine

1 name2 = InputBox("What is the name of the machine?", "Name of Machine")

'Ask the user for the number of machines that have been manufacturee

number = InputBox("How many of " & name2 & " have been manufactured?", "Amount of New Stock")

matching_machine2 = "No"

For i = 1 To 99
    If UCase(machine(i)) = UCase(name2) Then
    
        matching_machine2 = "Yes"

        'Check that the information is correct

        check2 = MsgBox("Are you sure you want to add " & number & " of " & name2 & " to the database?", vbYesNoCancel, "Confirm Amendment")

            If check2 = vbYes Then
            temp7 = availability(i)
            availability(i) = (temp7 + name)
            'Output new 'number in stock' value
            Cells(i + 6, 5).Value = availability(i)
            Else
            End
            End If
                  
    Else
    End If
Next i

'If there are no machines matching this name ask user to check if the spelling is correct

If matching_machine2 = "No" Then
MsgBox ("There are no machines in the database matching this name. Please ensure your spelling is correct!")
GoTo 1
Else
End If



End Sub
Thanks!
Lisa
Reply With Quote
  #2  
Old 04-03-2004, 02:27 PM
sseller's Avatar
sseller sseller is offline
Contributor
 
Join Date: Nov 2003
Location: Leeds UK
Posts: 804
Default

Hi Lisa

Shouldn't that be temp7 = number?
Reply With Quote
  #3  
Old 04-03-2004, 02:36 PM
Confused II Confused II is offline
Newcomer
 
Join Date: Apr 2004
Posts: 13
Default

Just realised what I've done-I've put name instead of number, knew it was something stupid!!It works now! Thanks for you help!!
Reply With Quote
  #4  
Old 04-03-2004, 02:36 PM
Vb_R_Us's Avatar
Vb_R_Us Vb_R_Us is offline
Banned
 
Join Date: Jan 2004
Location: Montreal,Québec,Canada
Posts: 61
Default

sorry, lysa i have no vlue about your question but only one thing NEVER USE GOTO, in university u use a goto in your program and the teacher give you 0.

can you post your complete program in a attached file


the problem can be : you spell the variable wrong
Reply With Quote
  #5  
Old 04-03-2004, 02:46 PM
Confused II Confused II is offline
Newcomer
 
Join Date: Apr 2004
Posts: 13
Smile File attatched!

I've attatched my code so far!
Our lecturer has told us that good programmers don't really use goto but he's given us some examples using goto and has said it's ok for us to use it!
I'd appreciate any suggestions though especially on what I can use instead of the goto!
Attached Files
File Type: bas Module1.bas (9.9 KB, 2 views)

Last edited by Confused II; 04-03-2004 at 02:57 PM.
Reply With Quote
  #6  
Old 04-03-2004, 02:48 PM
The Architect The Architect is offline
Freshman
 
Join Date: Mar 2004
Posts: 31
Default

Hey Confused II, a little tip. Always try to use the Hungarian notation technique. Hungarian notation is using prefixes such as str (for String), int (for Integer) etc. It makes easier reading for the programmer, either you or third party. I read your code and didn't know what some variables were for. Luckily, others must have figured it out as you got a reply, but just a tip for the future.

As for Goto, Vb R Us is correct. Goto is bad practice in object-orientated programming but it is perfectly acceptable in Error Handlers.
__________________
Hope... it is the quintessential human delusion; simultaneously the source of your greatest strength, and your greatest weakness.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Map/Array/Room(x,y), amount of enemies... Hardest problem I've encountered so far... Kronikle66 Game Programming 16 09-30-2003 02:07 PM
ADO Recorset Problem coco286 Database and Reporting 1 09-28-2003 09:08 PM
Problem with VB6->Excel jluisfer Excel 7 09-07-2003 07:46 AM
Help with problem with Excel Automation within VB6 seidenstud Word, PowerPoint, Outlook, and Other Office Products 1 12-18-2002 11:44 AM
Timers jemerico General 7 05-30-2001 05:30 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->