Another little problem!!

Confused II
04-03-2004, 03:21 PM
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!! :chuckle: Anyway, I'd appreciate any help!

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)
End If

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
End If

End Sub


04-03-2004, 03:27 PM
Hi Lisa

Shouldn't that be temp7 = number?

Confused II
04-03-2004, 03:36 PM
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!!

04-03-2004, 03:36 PM
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

Confused II
04-03-2004, 03:46 PM
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!

The Architect
04-03-2004, 03:48 PM
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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum