Jay1b Posted March 11, 2005 Posted March 11, 2005 When i first started to use VB.NET i wrote a large program using VB6 skills (not knowing about classes), i am just trying to convert this program into 'proper' VB.NET language. This code below allows me to enter data into the fields like this: Fields_OTT(1).FieldName = "Jay" Fields_OTT(2).FieldName = "Tom" Fields_OTT(1).FieldName = "Peter" This keeps the same structure for each of the three. Public strSettings As String Public strSeqNo As Integer Public intComPort As Integer Public strDestinationDirectory As String Public strJournalDirectory As String Public Structure StructField Public FieldName As String Public FieldStartPos As Integer Public FieldLength As Integer End Structure Public Fields_OTT() As StructField Public Fields_BIW() As StructField Public Fields_SSN() As StructField Trying to put this into a class has proved a nightmare. Could someone please direct me in doing so... Thanks Quote
*Experts* DiverDan Posted March 11, 2005 *Experts* Posted March 11, 2005 Hi Jay, Here's a simple example of one of my Public Structure Classes <Serializable()> Public Class stuRaceway Public RacewayType As String Public TradeSizeSAE As String Public TradeSizeMM As String Public DecimalSize As Double Public Diameter As Double Public Area As Double Public Unit As String Public Index As Integer End Class I have marked it as Serializable for file saving. You must create either a referance or a new instance of the Class to use it Dim Raceway as stuRaceway - for using the structure Dim Raceway as New stuRaceway - for creating new Raceways then: Raceway.RacewayType = 'blah etc. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Jay1b Posted March 14, 2005 Author Posted March 14, 2005 Thanks. But using Structures the way i was previously doing it, i could do the following. For i = 1 To 100 Do action = Fields_OTT(i).FieldName action = Fields_OTT(i).FieldStartPos action = Fields_OTT(i).FieldLength End For The way you suggested couldnt be done like this. (I've already thought about that). Edit: Unless this would work? Dim blah() As New ClassName Thanks again. Quote
*Experts* DiverDan Posted March 14, 2005 *Experts* Posted March 14, 2005 (edited) That's about what my post said.....and it does work. Dim Raceway as stuRaceway - for using the structure Dim Raceway as New stuRaceway - for creating new Raceways Are you using an array list for holding or extracting the information? As you may already know, Class structures are only the structure of a collection and not the collection itself. If you are using an ArrayList called Raceways that is either populated from file or from RAM then use: Dim Raceway as stuRaceway For Each Raceway in Raceways 'blah Next This utilizies the Raceway structure to obtain information from the ArrayList For adding new Raceways to the Arraylist use: For i = 0 to 100 Dim newRaceway As New stuRaceway 'assuming that you're filling the ArrayList from an existing array newRaceway.something = action(i) newRaceway.somethingelse = action(i + 1) 'etc. Raceways.Add(newRaceway) Next This adds new Raceways in the stuRaceway structure to the ArrayList - or whatever format of collection database you are using. Edited March 14, 2005 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.