There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot bsod computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop malware monitor network networking outlook outlook 2003 outlook express partition password printer problem problems ram router slow sound sprtcmd.exe trojan usb virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Tiny VB Error (Need Help)


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
DanTheMan888's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Mar 2008
Experience: Beginner
10-Mar-2008, 09:17 PM #1
Tiny VB Error (Need Help)
heres the download

http://h1.ripway.com/killswitcher888...cessingppt.zip

im getting a type missmatch
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
11-Mar-2008, 02:27 AM #2
Have you tried stepping through the code? Could you post the errant code block?

chris.
DanTheMan888's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Mar 2008
Experience: Beginner
11-Mar-2008, 05:58 AM #3
im trying to add stock to a file and i get type mismatches,
heres the code. oh and if you could download and have a look at it running it would be sweet . dont worry, its only one simple form

Private Type OneProduct
ProductID As Integer
Description As String * 18
Price As Currency
QuantityInStock As Integer
ReorderLevel As Integer
End Type
Dim Filename As String
Dim NumberOfRecords As Integer

Private Sub cmdAddRecord_Click()
Dim ProductID As OneProduct
Filename = App.Path & "\ex10_2_Products.dat"
Product.ProductID = txtProductID.Text
Product.Description = txtDescription.Text
Product.Price = txtPrice.Text
Product.QuantityInStock = txt.QuantityInStock.Text
Product.ReorderLevel = cboReorderLevel.Text
Open Filename For Random As #1 Len = Len(Product)
Put #1, NumberOfRecords + 1, Product
Close #1
NumberOfRecords = NumberOfRecords + 1
lblNumberOfRecords.Caption = NumberOfRecords
txtProductID.Text = ""
txtDesription.Text = ""
txtPrice.Text = ""
txtQuantityInStock.Text = ""
txtProductID.SetFocus
cboReorderLevel.Text = "50"
End Sub

Private Sub cmdDisplayFile_Click()
Dim Index As Integer
Dim DataToDisplay As String
Dim Quantity As String * 4
Dim Price As String * 6
Dim ReorderLevel As String * 3
Dim Product As OneProduct
Filename = App.Path & “ \ ex10_2_Products.dat”
lstDisplayFile.Clear
Open Filename For Random As #1 Len = Len(Product)
For Index = 1 To NumberOfRecords
Get #1, , Product
Quantity = Product.QuantityInStock
Price = Format(Product.Price, " Currency")
ReorderLevel = Product.ReorderLevel
DataToDisplay = Product.ProductID & " " & Product.Description _
& " " & Quantity & " " & Price & " " & ReorderLevel
Next Index
Close #1
End Sub

Private Sub cmdFindProductID_Click()
Dim RecordNumber As Integer
Dim Found As Boolian
Dim ProductID As String
Dim Product As OneProduct
ProductID = txtFindProduct.Text
RecordNumber = 0
Found = False
Filename = App.Path & “ \ ex10_2_Products.dat”
Open Filename For Random As #1 Len = Len(Product)
Do While (Not EOF(1)) And (Found = False)

RecordNumber = RecordNumber + 1
Get #1, RecordNumber, Product
If Product.ProductID = ProductID Then
Found = True
lblProductID.Caption = Product.ProductID
lblDesription.Caption = Product.Description
lblPrice.Caption = Product.Price
lblQuantityInStock.Caption = Product.QuantityInStock
lblReorderLevel.Caption = Product.ReorderLevel
End If
Loop
Close #1
If Not Found Then
MsgBox ("Product ID " & ProductID & " is not in the file")
End If
End Sub

Private Sub cmdFindRecord_Click()
Dim RecordNumber As Integer
Dim Product As OneProduct
Filename = App.Path & “ \ ex10_2_Products.dat”
RecordNumber = txtFindRecord.Text
If (RecordNumber > 0) And (RecordNumber <= NumberOfRecords) Then
Open Filename For Random As #1 Len = Len(Product)
Get #1, RecordNumber, Product
lblProductID.Caption = Product.ProductID
lblDesription.Caption = Product.Description
lblPrice.Caption = Product.Price
lblQuantityInStock.Caption = Product.QuantityInStock
lblReorderLevel.Caption = Product.ReorderLevel
Close #1
Else
MsgBox "Invalid record number"
End If
End Sub
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
11-Mar-2008, 06:39 AM #4
Well, I don't have Office anymore so I can't run it if it's an Office integration solution using VBA, and I don't have Visual Studio so I can't help there either. These are the lines I assume are throwing exceptions:
Product.ProductID = txtProductID.Text
[...]
Product.Price = txtPrice.Text
Product.QuantityInStock = txt.QuantityInStock.Text
Product.ReorderLevel = cboReorderLevel.Text
The properties ProductID, QuantityInStock, and ReorderLevel are dimensioned as Integer data types, and Price is dimensioned as a Currency data type. The assignments above are mismatches because of the implicit String data type of Text properties.

I don't know VB.NET but I imagine casting the types will help.
Product.ProductID = CInt(txtProductID.Text)
[...]
Product.Price = Format(txtPrice.Text, "Currency") ' don't know of a currency conversion function
Product.QuantityInStock = CInt(txt.QuantityInStock.Text)
Product.ReorderLevel = CInt(cboReorderLevel.Text)
I have a feeling the lines above were not part of the original code. So I assume the remainder of what you posted works correctly. I don't see any glaring problems, anyway.

Try my suggestions on a copy of the file and see how that works.

chris.
DanTheMan888's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Mar 2008
Experience: Beginner
11-Mar-2008, 08:53 PM #5
your rite abut whats wrong but not on how to fix it, the Cint still gives me missmatches
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
12-Mar-2008, 12:46 AM #6
Well, I don't know if there are nuances to casting in VB. Is it possible that the text box controls aren't instantiated or somehow have null values? All I know is that those lines are incorrectly type cast. Someone who knows more about VB will have to give you more useful advice.

chris.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:53 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.