Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / August 2005



Tip: Looking for answers? Try searching our database.

Need help with UDT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nobody You Know - 30 Aug 2005 00:05 GMT
I am /trying/ to  get the hang of udt's and random access files.  When
I press F5, the computer creates the file "items.dat", that is 514
bytes long.  All hex $00. Would someone please show me where I'm
screwing up?

Thanks,

---------------------------------------------

Private Type Item
  Number As Integer
  Description As String * 30
  Price As Currency
End Type

Dim NewItem As Item
Dim ItemCount As Integer

Option Base 1

Private Sub Form_Load()
  Open "a:\items.dat" For Random As 1
  For ItemCount = 1 To 5
      NewItem.Number = ItemCount
      NewItem.Description = "Item number " & Str(ItemCount)
      NewItem.Price = ItemCount
      Put #1, , Item
  Next ItemCount
  Close 1
  End
End Sub
Jim Mack - 30 Aug 2005 00:55 GMT
> I am /trying/ to  get the hang of udt's and random access files.  When
> I press F5, the computer creates the file "items.dat", that is 514
> bytes long.  All hex $00. Would someone please show me where I'm
> screwing up?

You're doing a couple of things wrong.  First is that you're not using Option Explicit, which would have shown you that you're Putting a variable named Item that you never declared... you meant NewItem.

Second is that you're using Random without specifying a record length, so records are Put at 128 byte intervals (the default Len).  You want to either use Binary mode, and calculate the offsets yourself, or specify the length in the Open statement:

 Open "a:\items.dat" For Random As 1 Len = Len(NewItem)

Signature

   Jim Mack
   MicroDexterity Inc
   www.microdexterity.com

> ---------------------------------------------
>
[quoted text clipped - 20 lines]
>    End
> End Sub
Nobody You Know - 30 Aug 2005 09:35 GMT
>> I am /trying/ to  get the hang of udt's and random access files.  When
>> I press F5, the computer creates the file "items.dat", that is 514
[quoted text clipped - 6 lines]
>
>  Open "a:\items.dat" For Random As 1 Len = Len(NewItem)

Thanks alot! Making those changes reduced the data file size by 87,912
bytes.  Over two-thirds of it's original size.
Lueko Willms - 30 Aug 2005 08:09 GMT
.    On  29.08.05
 wrote  nobody@nowhere.com (Nobody You Know)
    on  /COMP/LANG/BASIC/VISUAL/MISC
    in  e6v6h1pedfn2r3gm2iof7icusnj1e21c1e@4ax.com
 about  Need help with UDT

NYK>    For ItemCount = 1 To 5
NYK>        NewItem.Number = ItemCount
NYK>        NewItem.Description = "Item number " & Str(ItemCount)
NYK>        NewItem.Price = ItemCount
NYK>        Put #1, , Item
NYK>    Next ItemCount

  You are filling "NewItem" with data, but apperently you don't write  
it, instead you write "Item" which does not exist as variable.

Yours,
Lüko Willms                                     http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --

Das Buch muß erst ausgedroschen werden. -G.C.Lichtenberg
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.