Public CompanyName As String
Public Address As String
Public City As String
Public State As String
Public Zip As String
Public Sqs As Double
Public BidAmount As Currency
Public BidMaterial As String
Public Bid2Amount As Currency
Public Bid2Material As String
Public Sdate As String
Public BusYrs As Integer
Public Estimator As String
Public Email As String
Public Notes As String
Public Phones As String '(mshflexgrid gridPhones)
Public Tasks As String '(mshflexgrid grid2Column)
Code:
RoofCoCollection.cls
Private m_RoofCompany As Collection
' Add an RoofCo object to the collection.
Public Sub Add(ByVal emp As RoofCo, Optional ByVal key As Variant)
If IsMissing(key) Then
m_RoofCompany.Add emp
Else
m_RoofCompany.Add emp, key
End If
End Sub
' Return the number of items in the collection.
Public Function Count() As Long
Count = m_RoofCompany.Count
End Function
' Return an RoofCo object.
Public Function Item(ByVal Index As Variant) As RoofCo '
Set Item = m_RoofCompany(Index)
End Function
Public Sub Remove(ByVal Index As Variant)
m_RoofCompany.Remove Index
End Sub
Public Function NewEnum() As IUnknown
Set NewEnum = m_RoofCompany.[_NewEnum]
End Function
Private Sub Class_Initialize()
Set m_RoofCompany = New Collection
End Sub
How can this be done ?
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
it looks as though this info is for saving settings. I am trying to save the data created from the classes with the ability to add to the data or modify the data.
This is for a homeowner getting roof bids from different companies.
The insert image is not working on this site
Homeowner wants to compare different roof bids
here is what i mean http://roofgenius.com/Roof Bids.jpg
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Thanks I have code to save binary data. The problem i have ran into is saving and reading the data after opening using the collection object. to read and update the data
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
it looks as though this info is for saving settings.
Nope. It is exactly what you were asking for... how to save your class to a file. There are other ways of serializing class data, but thought I'd give you a link from msdn itself. Try searching this forum for those key words: serialize class
Insomnia is just a byproduct of, "It can't be done"
Nope. It is exactly what you were asking for... how to save your class to a file. There are other ways of serializing class data, but thought I'd give you a link from msdn itself. Try searching this forum for those key words: serialize class
Thanks LaVolpe, most of the example are for vb.net and most is over my head. I am a retired roofing contractor and need to stick with what i know
I have decided use a hidden msflexgrid feeding my collection that can be easily saved. and read back.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
You know there is no need for Binary File, or a class. What you have doing can be achieved using simply a collection (or UDT) and file output/input (or binary I guess). So are you loading it into the collection and into the flexgrid? I'm sure it works but there's no need to do the job twice, using the collection (or UDT) should be good enough to read/write your data.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
You know there is no need for Binary File, or a class. What you have doing can be achieved using simply a collection (or UDT) and file output/input (or binary I guess). So are you loading it into the collection and into the flexgrid? I'm sure it works but there's no need to do the job twice, using the collection (or UDT) should be good enough to read/write your data.
Thanks Max187Boucher
I would love to use a UDT as i used one a few times
I have used it for roof estimating and all the data belongs to that roof being estimated
What i am trying to do now has many roofing companies with each having having it's own data. After doing some reading I decided to use a class with a collection, never realized that saving and loading the data would be such an issue
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Sounds like a classic application for a database table, or even just a persisted Recordset. That's what I'd normally look at first, though there are lots of possibilities including JSON or XML. PropertyBags are native to VB's class persistance.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by dilettante
Sounds like a classic application for a database table, or even just a persisted Recordset. That's what I'd normally look at first, though there are lots of possibilities including JSON or XML. PropertyBags are native to VB's class persistance.
Thanks dilettante
About the last thing I'd consider is a UDT.
I was wondering when someone would say a database which for me would not work as i have tried in the past and ran into one problem after another mostly i think was installing on a users machine
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by dilettante
Sounds like a classic application for a database table, or even just a persisted Recordset. That's what I'd normally look at first, though there are lots of possibilities including JSON or XML. PropertyBags are native to VB's class persistance.
About the last thing I'd consider is a UDT.
What's wrong with a UDT? It's easy to work with for such a small program.
Re: [RESOLVED] How to Save classes to binary file vb6
I think Max may not have realized that the saving and rereading the data was the critical part for you, not the using of the UDTs, and did not have time to write the saving and loading code after creating the example as far as he did.
So, I extended the example a little further, but I would back up the data file regularly since it would be easy to wipe out if one hit the save button, without having loaded.
There definitely should be multiple safeguards, but this is just a quick example of saving the data and rereading it, and using the Msgbox code Max already provided to show a few values from different elements of the array so you can verify the load did load data back in (hit save, close program, restart program, hit load, then examine using the display button and textbox).
I added two buttons at the bottom (cmdSave and cmdLoad") and another button and textbox for examination. You enter an index number in the textbox, and click the button and it will popup the msgbox Max provided to display the fields he chose to show.
If you open other file in this application, or want to use this for reuse in another program, you should use FreeFile to get the file handle, but there is no conflict with code outside your application to use a hardcoded literal value.
I'll post the modifications I made to the file. You will need to change the path (and name if you want) of the data file of course, and add the buttons and textbox.
Code:
'In the declaration area added
Private ArrayDim As Integer 'Hold the current dimension (ubound) of the data array (initially 100)
Private Sub cmdDisplay_Click()
display Val(Text1.Text) 'display some data for the index specified in Text1 textbox
End Sub
Private Sub cmdSave_Click()
ArrayDim = UBound(RoofCompany) 'In case size changed while running
Open "C:\c\roof.dat" For Binary As #1
Put #1, , ArrayDim 'Write out the array dimensions in case it increases
Put #1, , RoofCompanyTotal 'Write out the total used in the array
Put #1, , Info 'Perhaps don't need to save this, but in case the mapping changes
Put #1, , RoofCompany 'Save the array of information
Close #1
End Sub
Private Sub cmdLoad_Click()
Open "C:\c\roof.dat" For Binary As #1
Get #1, , ArrayDim 'Read in the array dimension
ReDim RoofCompany(ArrayDim) 'Redimension the array to the size saved
Get #1, , RoofCompanyTotal 'Read how many entries used
Get #1, , Info 'Reread the mapping array
Get #1, , RoofCompany 'Load the array with the data saved
Close #1
End Sub
Private Sub Form_Load()
ArrayDim = 100
ReDim RoofCompany(ArrayDim)
With Info
' .... modified to initialize ArrayDim, the rest of the code in the sub is the same
End Sub
'Changed Command1_Click to call the display sub to show the msgbox, so we could use it from the Display button as well
Private Sub Command1_Click()
Add_Company
display RoofCompanyTotal - 1
'Saving/Read values
End Sub
That its, for what its worth.
Last edited by passel; Aug 30th, 2014 at 03:58 PM.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by passel
I think Max may not have realized that the saving and rereading the data was the critical part for you, not the using of the UDTs, and did not have time to write the saving and loading code after creating the example as far as he did.
So, I extended the example a little further, but I would back up the data file regularly since it would be easy to wipe out if one hit the save button, without having loaded.
There definitely should be multiple safeguards, but this is just a quick example of saving the data and rereading it, and using the Msgbox code Max already provided to show a few values from different elements of the array so you can verify the load did load data back in (hit save, close program, restart program, hit load, then examine using the display button and textbox).
I added two buttons at the bottom (cmdSave and cmdLoad") and another button and textbox for examination. You enter an index number in the textbox, and click the button and it will popup the msgbox Max provided to display the fields he chose to show.
If you open other file in this application, or want to use this for reuse in another program, you should use FreeFile to get the file handle, but there is no conflict with code outside your application to use a hardcoded literal value.
I'll post the modifications I made to the file. You will need to change the path (and name if you want) of the data file of course, and add the buttons and textbox.
Code:
'In the declaration area added
Private ArrayDim As Integer 'Hold the current dimension (ubound) of the data array (initially 100)
Private Sub cmdDisplay_Click()
display Val(Text1.Text) 'display some data for the index specified in Text1 textbox
End Sub
Private Sub cmdSave_Click()
ArrayDim = UBound(RoofCompany) 'In case size changed while running
Open "C:\c\roof.dat" For Binary As #1
Put #1, , ArrayDim 'Write out the array dimensions in case it increases
Put #1, , RoofCompanyTotal 'Write out the total used in the array
Put #1, , Info 'Perhaps don't need to save this, but in case the mapping changes
Put #1, , RoofCompany 'Save the array of information
Close #1
End Sub
Private Sub cmdLoad_Click()
Open "C:\c\roof.dat" For Binary As #1
Get #1, , ArrayDim 'Read in the array dimension
ReDim RoofCompany(ArrayDim) 'Redimension the array to the size saved
Get #1, , RoofCompanyTotal 'Read how many entries used
Get #1, , Info 'Reread the mapping array
Get #1, , RoofCompany 'Load the array with the data saved
Close #1
End Sub
Private Sub Form_Load()
ArrayDim = 100
ReDim RoofCompany(ArrayDim)
With Info
' .... modified to initialize ArrayDim, the rest of the code in the sub is the same
End Sub
'Changed Command1_Click to call the display sub to show the msgbox, so we could use it from the Display button as well
Private Sub Command1_Click()
Add_Company
display RoofCompanyTotal - 1
'Saving/Read values
End Sub
That its, for what its worth.
Thanks for adding that.
You are right about saving/loading and about the freefile function few yrs ago i had a problem that would only show up randomly
After days finally fixed the problem using FreeFile, been using it ever since.
As far as the saving/loading I wrote a roof estimating program as a retired roofing contractor and rookie coder and everything(variables)in the project belonged to to the roof estimate.
This new program has many variables belonging to different companies. This really thru me a curve.
I am glad you people are here
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by passel
I think Max may not have realized that the saving and rereading the data was the critical part for you, not the using of the UDTs, and did not have time to write the saving and loading code after creating the example as far as he did.
So, I extended the example a little further, but I would back up the data file regularly since it would be easy to wipe out if one hit the save button, without having loaded.
There definitely should be multiple safeguards, but this is just a quick example of saving the data and rereading it, and using the Msgbox code Max already provided to show a few values from different elements of the array so you can verify the load did load data back in (hit save, close program, restart program, hit load, then examine using the display button and textbox).
I added two buttons at the bottom (cmdSave and cmdLoad") and another button and textbox for examination. You enter an index number in the textbox, and click the button and it will popup the msgbox Max provided to display the fields he chose to show.
If you open other file in this application, or want to use this for reuse in another program, you should use FreeFile to get the file handle, but there is no conflict with code outside your application to use a hardcoded literal value.
I'll post the modifications I made to the file. You will need to change the path (and name if you want) of the data file of course, and add the buttons and textbox.
Code:
'In the declaration area added
Private ArrayDim As Integer 'Hold the current dimension (ubound) of the data array (initially 100)
Private Sub cmdDisplay_Click()
display Val(Text1.Text) 'display some data for the index specified in Text1 textbox
End Sub
Private Sub cmdSave_Click()
ArrayDim = UBound(RoofCompany) 'In case size changed while running
Open "C:\c\roof.dat" For Binary As #1
Put #1, , ArrayDim 'Write out the array dimensions in case it increases
Put #1, , RoofCompanyTotal 'Write out the total used in the array
Put #1, , Info 'Perhaps don't need to save this, but in case the mapping changes
Put #1, , RoofCompany 'Save the array of information
Close #1
End Sub
Private Sub cmdLoad_Click()
Open "C:\c\roof.dat" For Binary As #1
Get #1, , ArrayDim 'Read in the array dimension
ReDim RoofCompany(ArrayDim) 'Redimension the array to the size saved
Get #1, , RoofCompanyTotal 'Read how many entries used
Get #1, , Info 'Reread the mapping array
Get #1, , RoofCompany 'Load the array with the data saved
Close #1
End Sub
Private Sub Form_Load()
ArrayDim = 100
ReDim RoofCompany(ArrayDim)
With Info
' .... modified to initialize ArrayDim, the rest of the code in the sub is the same
End Sub
'Changed Command1_Click to call the display sub to show the msgbox, so we could use it from the Display button as well
Private Sub Command1_Click()
Add_Company
display RoofCompanyTotal - 1
'Saving/Read values
End Sub
That its, for what its worth.
Is this a typo or ?
Private Sub Command1_Click()
Add_Company
display RoofCompanyTotal - 1
Gives this error: sub or function not defined
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Looks like I left the display sub off the post.
I copied the code that Max had that displayed the msgbox into a new sub called display so it could be called from where it originally was (in the Command1_Click, and from cmdDisplay_Click.
Code:
Private Sub display(idx As Integer)
With RoofCompany(idx)
MsgBox "Name: " & .CompanyName & vbNewLine & _
"Address: " & .Address & vbNewLine & _
"Cell: " & .Phones.Cell
End With
End Sub
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by passel
Looks like I left the display sub off the post.
I copied the code that Max had that displayed the msgbox into a new sub called display so it could be called from where it originally was (in the Command1_Click, and from cmdDisplay_Click.
Code:
Private Sub display(idx As Integer)
With RoofCompany(idx)
MsgBox "Name: " & .CompanyName & vbNewLine & _
"Address: " & .Address & vbNewLine & _
"Cell: " & .Phones.Cell
End With
End Sub
Thanks
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Did you get it to work isnoend? If not maybe list the problems you are running into, with passel's code you can load/save all the data.
If you need to delete some entries you'll have to fix the UDT (rearrange it) and redim preserve it.
Edit:
I simply added passel's code with mine didn't update much because i don't have the original project (yours) so a little by little will be easier for you to add/modify your project.
Last edited by Max187Boucher; Aug 31st, 2014 at 12:12 PM.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
Did you get it to work isnoend? If not maybe list the problems you are running into, with passel's code you can load/save all the data.
If you need to delete some entries you'll have to fix the UDT (rearrange it) and redim preserve it.
Edit:
I simply added passel's code with mine didn't update much because i don't have the original project (yours) so a little by little will be easier for you to add/modify your project.
Thanks for your help.
I got code from another site(Experts Exchange) that seems to work without doing a lot of rewrite with the classes/collection i have:
Added a structure to the general declarations section of the RoofCoCollection class and added code to the class terminate() event to persist the data.
Code:
Option Explicit
Private Type Roof_struc
CompanyName As String
Address As String
City As String
State As String
Zip As String
Sqs As Double
BidAmount As Currency
BidMaterial As String
Bid2Amount As Currency
Bid2Material As String
Sdate As String
BusYrs As Integer
Estimator As String
Email As String
Notes As String
Phones As String
Tasks As String
End Type
'===================================
'your existing code remains unchanged here
'===================================
Private Sub Class_Terminate()
Dim intFN As Integer
Dim vItem As Variant
Dim roofthing As Roof_struc
intFN = FreeFile
Open App.Path & "\" & HomeOwnerName & ".bid" For Binary As #intFN
For Each vItem In m_RoofCompany
roofthing.CompanyName = vItem.CompanyName
roofthing.Address = vItem.Address
roofthing.City = vItem.City
roofthing.State = vItem.State
roofthing.Zip = vItem.Zip
roofthing.Sqs = vItem.Sqs
roofthing.BidAmount = vItem.BidAmount
roofthing.BidMaterial = vItem.BidMaterial
roofthing.Bid2Amount = vItem.Bid2Amount
roofthing.Bid2Material = vItem.Bid2Material
roofthing.Sdate = vItem.Sdate
roofthing.BusYrs = vItem.BusYrs
roofthing.Estimator = vItem.Estimator
roofthing.Email = vItem.Email
roofthing.Notes = vItem.Notes
roofthing.Phones = vItem.Phones
roofthing.Tasks = vItem.Tasks
Put #intFN, , roofthing
Next
Close #intFN
End Sub
Get the data back
Code:
Public Function Populate(ByVal parmPathAndFilename As String)
Dim intFN As Integer
Dim vItem As Variant
Dim roofthing As Roof_struc
Dim clsRoof As RoofCo
intFN = FreeFile
If Len(Dir(parmPathAndFilename)) = 0 Then
Populate = 53 'file not found
Exit Function
End If
On Error Resume Next
Open parmPathAndFilename For Binary As #intFN
If Err <> 0 Then
Populate = Err.Number
Exit Function
End If
Do Until EOF(intFN)
Get #intFN, , roofthing
clsRoof.CompanyName = roofthing.CompanyName
clsRoof.Address = roofthing.Address
clsRoof.City = roofthing.City
clsRoof.State = roofthing.State
clsRoof.Zip = roofthing.Zip
clsRoof.Sqs = roofthing.Sqs
clsRoof.BidAmount = roofthing.BidAmount
clsRoof.BidMaterial = roofthing.BidMaterial
clsRoof.Bid2Amount = roofthing.Bid2Amount
clsRoof.Bid2Material = roofthing.Bid2Material
clsRoof.Sdate = roofthing.Sdate
clsRoof.BusYrs = roofthing.BusYrs
clsRoof.Estimator = roofthing.Estimator
clsRoof.Email = roofthing.Email
clsRoof.Notes = roofthing.Notes
clsRoof.Phones = roofthing.Phones
clsRoof.Tasks = roofthing.Tasks
add clsRoof
Loop
Close #intFN
Populate = 0
End Function
This seems to work and even with my limited coding knowledge
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
The only thing that seems to be missing is keeping track of how many instances of the class were saved in the file.
It is just reading until it reaches the end of the file.
Since you are reusing the same binary file, the size of the file will grow depending on how many items are written to it, but it will never shrink if you write less data to it.
So, if you ever write fewer objects to the file in the future (you've removed some instances from your collection), when you save those will be written to the "front" of the file, but old ones will remain at the "back" of the file.
The next time you load, you will populate your collection with the current data saved, plus the old duplicate instances at the end of the file.
I usually write the count of how many "records" are being written to the file first, so I know how many to read, and ignore any "garbage" at the end of the file.
But, a couple of other approaches would be,
1. Have the saving code delete the binary file, before opening it, creating a fresh file that only has new data in it (if the write fails, you can be hurting since you deleted the file, so...)
2. have the saving code rename the old file as a backup, and thereby opening a new file when it does the open, so again you only have the latest data in the file.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by passel
The only thing that seems to be missing is keeping track of how many instances of the class were saved in the file.
It is just reading until it reaches the end of the file.
Since you are reusing the same binary file, the size of the file will grow depending on how many items are written to it, but it will never shrink if you write less data to it.
So, if you ever write fewer objects to the file in the future (you've removed some instances from your collection), when you save those will be written to the "front" of the file, but old ones will remain at the "back" of the file.
The next time you load, you will populate your collection with the current data saved, plus the old duplicate instances at the end of the file.
I usually write the count of how many "records" are being written to the file first, so I know how many to read, and ignore any "garbage" at the end of the file.
But, a couple of other approaches would be,
1. Have the saving code delete the binary file, before opening it, creating a fresh file that only has new data in it (if the write fails, you can be hurting since you deleted the file, so...)
2. have the saving code rename the old file as a backup, and thereby opening a new file when it does the open, so again you only have the latest data in the file.
Thanks for the feedback. Have found that fixing stuff before i run into trouble is a lot easier (such as using FreeFile)
I have been under the impression that when saving a file the saved file is replaced with the new contents if that
is not the case then it seems that this would be the best way when saving:
Backup the saved file
Kill Filename
save the file
Right now i am having an issue with EE coder in referencing the saved data
I keep getting function or sub not found when trying to open the data from a command button.
He says that public functions in a class are different than in a module(new to me)
Hopefully I can get this resolved and get on with project.
Never thought this going to be such an issue.
Read a lot about classes-collections and never did i see that saving-opening is an issue
i am glad you people are here
Public Function Populate
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by isnoend07
...
I have been under the impression that when saving a file the saved file is replaced with the new contents...
In VB6,
a file opened for "Output" will replace the contents of the file. You would open for "Append" to add new content to the end of the file. You cannot write into the middle of the file to replace or update content.
Files open for "Random" or "Binary" allow writing to any point in the file, the location being a byte offset for binary, and a "record" offset for random, and you don't have to start writing at the first byte of the file.
Since you can write any place in the file, you can update a portion of the file, e.g. a particular record of a random file, but leave the rest of the file alone.
Since you can update any portion of the file, opening a file in binary or random mode can't wipe out the rest of the file, or truncate the file, that would defeat the purpose of that type of access.
Re: [RESOLVED] How to Save classes to binary file vb6
Still don't understand why use a class for this.... A class is usually used to create different instance for a control to be used separately, but your program only needs 1 instance, or in my opinion none. All you need is to store or read data. Since you won't have 1million of difference companies, that's why I said a simple udt will be your best option. If you had a whole bunch of information to store and you have to replace information then you use a database and not a class.
I wish you could PM me your program, or to passel it would be done by now. We gave you a solution but you keep trying to use a class, I'm not saying it's impossible with a class, but you don't need different instance to save/open information. There is no need for properties either your not creating a control. A module would of been better solution.
How long can it take to save the UDT, a second or two?
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
Still don't understand why use a class for this.... A class is usually used to create different instance for a control to be used separately, but your program only needs 1 instance, or in my opinion none. All you need is to store or read data. Since you won't have 1million of difference companies, that's why I said a simple udt will be your best option. If you had a whole bunch of information to store and you have to replace information then you use a database and not a class.
I wish you could PM me your program, or to passel it would be done by now. We gave you a solution but you keep trying to use a class, I'm not saying it's impossible with a class, but you don't need different instance to save/open information. There is no need for properties either your not creating a control. A module would of been better solution.
How long can it take to save the UDT, a second or two?
Thanks for your reply I am not married to a class. I posted to another site on how to do this and never got an answer. So after much investigating-reading i decided on a collection class(never read anything about saving/opening the data was an issue) what has got me stumped after writing a roof estimating program was the fact that
every thing i wrote belonged to the one instance of the roof all variables everything.
With this program not only are the owners roof measurements saved under his name, but the roofing companies all have their own data this is the part that had me stumped. in using the class my plan was to have the homeowners data saved to a file and the roofing companies data saved to another file.
In using the class i posted i thought that was the way to go, but now i have ran into issues with it and i do not understand classes very much eg the save routine is in the class terminate event which i cannot control. I wish i knew more about coding like you guys
I will post the project any help would sure be appreciated
i added a module with udt fields (
Last edited by isnoend07; Sep 1st, 2014 at 11:46 AM.
Reason: more to add
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
I made a new project, trying to make it similar to yours. Here is what is done so far, I was also thinking about using a listview for the RECAP instead of flexgrid... Let me know what you think.
I will finish the listview (recap) next and the deletion of an item from the UDT and file.
Re: [RESOLVED] How to Save classes to binary file vb6
Thanks for taking the time for this. Never used a listview i prefer a flexgrid because I have used them so much my last project had about 35 of them. my main concern was saving and opening and being able to work with the saved data. Not sure if the example i sent you had the ability
to click a name in the main list of companies (gridMain) and the bid details would fill the textboxes. I will test with your example and probably
have questions. thanks a ton, i will be back
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
I didn't finish the maingrid yet, I made it all from scratch except the pic notes.
I will add the function to load into the textbox fields tonight and see how much time I will have and try to finish it as much as I can.
As of now it's just to show you what I had done, look at my code then look at yours I found your code hard to read or work with it has so many code commented out and just for example look at how you were populating the grids for phones and tasks you were loading the rows and columns like 3 times in a row I made it a bit more clear and simple. I will post the update tonight to keep you posted.
I moved the buttons and made a menu, looks better to me, if not you can easily change that yourself when I'm done.
Re: [RESOLVED] How to Save classes to binary file vb6
thanks' your design certainly looks better, i usually leave the looks part for last. In looking at your code i can see you are much better than me at writing it, but your advanced methods are hard for me to read and follow, for example on form load i see this:
I know doing this is important, but i do not see the purpose
Also the the udt's i know all serve a purpose, but i cannot determine what
Private Type Info_UDT
Private Type Phone_UDT
Private Type RoofCompany_UDT
Private RoofCompany() As RoofCompany_UDT
Private RoofCompanyTotal As Integer
Private Info As Info_UDT
I think that one tracks which companies data belongs to which company.
the Private Type Phone_UDT I was going to make it a part of another udt
as both columns are editable and no data is pre-set this way a owner can put peoples names or whatever in the
Phone names column
I have in the past used the .clip property of the MsHflexgrid to produce a string of the contents
The string was part of a udt
The top right grid only the 2nd column is editable.so the clip only does the 2nd column.
I am much better at determing what need to be done ,but fall short on the code writing.
When writing this i thought of something else to consider:
What if the homeowner wants to enter his sons or neighbors roof bids
Then the fileName needs changing to HomeOwners-Name,address,RoofBids.dat set in roofbidder
a form not supplied This is the main form in this project where the homeowner can enter his roof measurments and the squares are calculated.
You are so advanced from me in writing code that it makes it difficult with all my rookie mistakes
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
I made a new project, trying to make it similar to yours. Here is what is done so far, I was also thinking about using a listview for the RECAP instead of flexgrid... Let me know what you think.
I will finish the listview (recap) next and the deletion of an item from the UDT and file.
Sorry if it's taking a bit longer to finish
I have been using this for managing grids contents
Code:
Sub SetPhoneClip()
With gridPhones
.Row = 1
.Col = 0
.ColSel = .Cols - 1
.RowSel = .Rows - 1
mstrPhoneNumbersClip = .Clip
.Row = 0
.Col = 0
End With
End Sub
Sub GetPhones()
With gridPhones
.Row = 1
.Col = 0
.ColSel = .Cols - 1
.RowSel = .Rows - 1
.Clip = mstrPhoneNumbersClip
.Row = 0
.Col = 0
End With
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
I am trying to make it easy (not advanced ) but yes when somebody else writes the code it can get confusing, one of the reason why I like to post the project not complete, this way you can see the progress and what does what. I tried looking at your code but I don't like that your code has more then half commented out (in your head you know what it is) but just looking at it to me doesn't make sense.
I can update it a bit tonight and then maybe I could explain or add comments of what is what.
The Phone_UDT is just to store all numbers instead of cramming all in one string and then having to split to get the numbers separately. Easy to read/write the code, look's cleaner.
I am trying to use the same design of your project so you still understand what is what. I am not trying to make it look nice, but just not ass messy. I am no expert but I like to help other people which might know a bit less than me. I will try to work with you to create what you need, if it's getting too complicated let me know.
I could use your project but then it is harder for me to modify. Once I finish the main grid (RECAP) then maybe it will help you understand how to use my UDT better. Will post back tonight with an update (hopefully I don't get distracted).
Edit:
The reason why I wanted to add listview is when you select a company from the list it would select the whole row and it is as easy to edit as a flxgrid.
Last edited by Max187Boucher; Sep 3rd, 2014 at 06:41 PM.
Re: [RESOLVED] How to Save classes to binary file vb6
Thanks for your comments
I hope the listview is easy for me to code. Since i posted i wrote code to delete a record.
It looks at the name in txtCompany then finds it in the GridMain, removes the row using GridMain.remove row
Then resizes the grid to make it shorter.
You mentioned splitting the GridPhones I have used the .clip property to put the data in a module level string eg;
Sub SetPhoneClip()
With gridPhones
.row = 1
.Col = 0
.ColSel = .Cols - 1
.RowSel = .Rows - 1
mstrPhoneNumbersClip = .Clip
.row = 0
.Col = 0
End With
End Sub
re-populate the grid when needed:
Sub ClipToPhones()'put the saved data
With gridPhones
.row = 1
.Col = 0
.ColSel = .Cols - 1
.RowSel = .Rows - 1
.Clip = mstrPhoneNumbersClip
.row = 0
.Col = 0
End With
End Sub
I am curious about the listview, why would you want to select the whole row ?
My plan for the GridMain: When form is opened the data from the file is added to it and the grid is sized to fit the data as each row is added
When i look at this code
Get #FF, , ArrayDim
ReDim RoofCompany(ArrayDim)
Get #FF, , RoofCompanyTotal
Get #FF, , Info
Get #FF, , RoofCompany
I know they will hold the saved data, but how to get at it i am in the dark
At least i can read the code. I got help creating a page with Java Script to me was totally unreadable eg:
t2 = ""||/^(\d+)?([.]?\d{0,2})?$/.test(text)===false?t2 = "Input Numbers Only":t2="";
I thought to myself these people must be from another planet.
What i really need is how to get to the saved data, maybe then i will be able to follow better
Thanks again for your help.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
I used a flexgrid just to keep the looks of your program so don't worry about listview for now.
For getting the information you asked to save a class as binary file, so I am saving the udt as binary, which passel gave you a nice example to save/load to binary. So what we are doing is saving the whole RoofCompany (UDT) array which holds all the information.
For the first roofcompany information (once loaded) you would write this
Code:
Msgbox RoofCompany(0).CompanyName
For second roofcompany you write RoofCompany(1).CompanyName
If you need the squares then you use RoofCompany(1).Sqs
I added the populate function but didnt upload the file yesterday was a bit busy and i didn't add the delete function yet.
I will upload tonight with the delete function, meaning it will be closer to being done... Still missing the notes/phone#/tasks then we can readjust what things to work with your main form which I havent really had a look at it.
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
I used a flexgrid just to keep the looks of your program so don't worry about listview for now.
For getting the information you asked to save a class as binary file, so I am saving the udt as binary, which passel gave you a nice example to save/load to binary. So what we are doing is saving the whole RoofCompany (UDT) array which holds all the information.
For the first roofcompany information (once loaded) you would write this
Code:
Msgbox RoofCompany(0).CompanyName
thanks for adding that,now i see how it works I have added this for testing to fill the textboxes and grids. I Know it can be a pain when testing
Code:
Sub FillSampleData()
Select Case txtInfo(0)
Case ""
txtInfo(0) = "Arcade Roofing"
txtInfo(1) = "1125 Bart rd"
txtInfo(2) = "08/04/14"
txtInfo(3) = "Reno"
txtInfo(4) = "NV"
txtInfo(5) = "88475"
txtInfo(6) = "Bill Philips"
txtInfo(7) = "$3268.00"
txtInfo(8) = "$32.48"
txtInfo(9) = "35yr comp"
txtInfo(10) = "[email protected]"
txtInfo(11) = "40yr comp"
txtInfo(12) = "$3645.00"
txtInfo(13) = "8"
Me.txtNotes = "Roof Estimater was 1 hour late, with no call"
With FlxGrd(0)
.TextMatrix(1, 0) = "Office"
.TextMatrix(1, 1) = "457-549-5521"
.TextMatrix(2, 0) = "Joe Philips Cell"
.TextMatrix(2, 1) = "457-327-5547"
.TextMatrix(3, 0) = "Office"
.TextMatrix(3, 1) = "457-549-5521"
End With
With FlxGrd(1)
.TextMatrix(1, 1) = "8 days"
.TextMatrix(2, 1) = "Yes"
.TextMatrix(3, 1) = "Yes"
.TextMatrix(4, 1) = "Yes"
.TextMatrix(5, 1) = "Yes"
.TextMatrix(6, 1) = "No"
End With
Add_Company
mSave_Click
Case "Arcade Roofing"
ClearData
txtInfo(0) = "Bills Roofing"
txtInfo(1) = "2547 Oak Ave"
txtInfo(2) = "08/01/14"
txtInfo(3) = "Reno"
txtInfo(4) = "NV"
txtInfo(5) = "88478"
txtInfo(6) = "Bill Jones"
txtInfo(7) = "$3568.00"
txtInfo(8) = "32.48"
txtInfo(9) = "35yr comp"
txtInfo(10) = "[email protected]"
txtInfo(11) = "40yr comp"
txtInfo(12) = "$3985.00"
txtInfo(13) = "12"
Me.txtNotes = "Contract was very Vague"
With FlxGrd(0)
.TextMatrix(1, 0) = "Office"
.TextMatrix(1, 1) = "427-624-5799"
.TextMatrix(2, 0) = "Bill Philips Cell"
.TextMatrix(2, 1) = "427-624-2554"
.TextMatrix(3, 0) = "Office"
.TextMatrix(3, 1) = "427-624-5714"
End With
With FlxGrd(1)
.TextMatrix(1, 1) = "5 days"
.TextMatrix(2, 1) = "No"
.TextMatrix(3, 1) = "No"
.TextMatrix(4, 1) = "No"
.TextMatrix(5, 1) = "No"
.TextMatrix(6, 1) = "No"
End With
Add_Company
mSave_Click
Case "Bills Roofing"
ClearData
txtInfo(0) = "John Doe Roofing"
txtInfo(1) = "367 main ave Ave"
txtInfo(2) = "08/08/14"
txtInfo(3) = "Reno"
txtInfo(4) = "NV"
txtInfo(5) = "88611"
txtInfo(6) = "Joe Garvy"
txtInfo(7) = "$3124.00"
txtInfo(8) = "31.00"
txtInfo(9) = "35yr comp"
txtInfo(10) = "[email protected]"
txtInfo(11) = "40yr comp"
txtInfo(12) = "$3485.00"
txtInfo(13) = "2"
Me.txtNotes = "+ Estimator was late but called"
With FlxGrd(0)
.TextMatrix(1, 0) = "Office"
.TextMatrix(1, 1) = "775-547-5214"
.TextMatrix(2, 0) = "Joe Garvy Cell"
.TextMatrix(2, 1) = "775-548-6621"
.TextMatrix(3, 0) = "Emergency"
.TextMatrix(3, 1) = "775-547-5215"
End With
With FlxGrd(1)
.TextMatrix(1, 1) = "10 days"
.TextMatrix(2, 1) = "Yes"
.TextMatrix(3, 1) = "No"
.TextMatrix(4, 1) = "Yes"
.TextMatrix(5, 1) = "Yes"
.TextMatrix(6, 1) = "Yes"
End With
Case "John Doe Roofing"
ClearData
txtInfo(0) = "Skyline Roofing"
txtInfo(1) = "1476 Rock Canyon rd"
txtInfo(2) = "08/03/14"
txtInfo(3) = "Reno"
txtInfo(4) = "NV"
txtInfo(5) = "88541"
txtInfo(6) = "Kobe Smith"
txtInfo(7) = "$2924.00"
txtInfo(8) = "30.00"
txtInfo(9) = "35yr comp"
txtInfo(10) = "[email protected]"
txtInfo(11) = "40yr comp"
txtInfo(12) = "$3124.00"
txtInfo(13) = "8"
Me.txtNotes = "+ Estimtor left very descripted brochures"
With FlxGrd(0)
.TextMatrix(1, 0) = "Office"
.TextMatrix(1, 1) = "775-554-2267"
.TextMatrix(2, 0) = "Kobe Smith Cell"
.TextMatrix(2, 1) = "775-551-6547"
.TextMatrix(3, 0) = "Emergency"
.TextMatrix(3, 1) = "775-551-6147"
End With
With FlxGrd(1)
.TextMatrix(1, 1) = "12 days"
.TextMatrix(2, 1) = "No"
.TextMatrix(3, 1) = "No"
.TextMatrix(4, 1) = "No"
.TextMatrix(5, 1) = "No"
.TextMatrix(6, 1) = "No"
End With
Add_Company
mSave_Click
Case Else
ClearData
End Select
End Sub
Sub ClearData()
Dim i As Integer
Dim r As Integer
Dim c As Integer
For i = 0 To 13
txtInfo(i) = ""
Next
With FlxGrd(0)
For r = 1 To .Rows - 1
For c = 0 To .Cols - 1
.TextMatrix(r, c) = ""
Next
Next
End With
With FlxGrd(0)
For r = 1 To .Rows - 1
For c = 1 To .Cols - 1
.TextMatrix(r, c) = ""
Next
Next
End With
With FlxGrd(1)
For r = 1 To .Rows - 1
.TextMatrix(r, 1) = ""
Next
End With
End Sub
thanks again
For second roofcompany you write RoofCompany(1).CompanyName
If you need the squares then you use RoofCompany(1).Sqs
I added the populate function but didnt upload the file yesterday was a bit busy and i didn't add the delete function yet.
I will upload tonight with the delete function, meaning it will be closer to being done... Still missing the notes/phone#/tasks then we can readjust what things to work with your main form which I havent really had a look at it.
I'm on my iPhone so I can't do much
Thanks again
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Re: [RESOLVED] How to Save classes to binary file vb6
Ok here is my new update. The updates that now work are...
-Notes
-Save (updates udt and file)
-txtEdit
-Populate
Still working on the delete_company function (havent started yet)
Then I will add the phones to udt and phone names like Owner's Phone and Estimator Phone/fax/office...
Then I will add the tasks (to save to udt and file)
Re: [RESOLVED] How to Save classes to binary file vb6
Originally Posted by Max187Boucher
Ok here is my new update. The updates that now work are...
-Notes
-Save (updates udt and file)
-txtEdit
-Populate
Still working on the delete_company function (havent started yet)
Looking at
Then I will add the phones to udt and phone names like Owner's Phone and Estimator Phone/fax/office...
Then I will add the tasks (to save to udt and file)
A little bit a a time we'll get there.
Thank for adding that
Couple things the phone grid both cols are editable the task grid only the last col is editable
nice back color for txtEdit.BackColor = RGB(235, 235, 235) light gray.
still looking
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders