 |
 |

04-03-2004, 02:21 PM
|
|
Newcomer
|
|
Join Date: Apr 2004
Posts: 13
|
|
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
|
|

04-03-2004, 02:27 PM
|
 |
Contributor
|
|
Join Date: Nov 2003
Location: Leeds UK
Posts: 804
|
|
|
Hi Lisa
Shouldn't that be temp7 = number?
|
|

04-03-2004, 02:36 PM
|
|
Newcomer
|
|
Join Date: Apr 2004
Posts: 13
|
|
|
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, 02:36 PM
|
 |
Banned
|
|
Join Date: Jan 2004
Location: Montreal,Québec,Canada
Posts: 61
|
|
|
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
|
|

04-03-2004, 02:46 PM
|
|
Newcomer
|
|
Join Date: Apr 2004
Posts: 13
|
|
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!
|
Last edited by Confused II; 04-03-2004 at 02:57 PM.
|

04-03-2004, 02:48 PM
|
|
Freshman
|
|
Join Date: Mar 2004
Posts: 31
|
|
|
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.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|