VB5 program

Electronics Computer Programming Q&A
Post Reply
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

VB5 program

Post by Mike »

I have a web site that lets users order products and it sends the info from the form to me. It is displayed as follows:<p>FirstName=name&Lastname=name&<p>There is First Name, Last Name, Address, City, State, Zip Code, Phone Number, an insurance checkbox, and two hidden fields with the item # and price, named Item and Price. I need a program that will open the file, and read the information seperated by the & sign. For example, the FirstName's value would display in a label labeled First Name. Can this be done?<p>Thank you, Mike
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: VB5 program

Post by bodgy »

Wouldn't Delphi or VB or VC allow direct hooks into your file?<p>Well I know Delphi comes with all the database engines apart from SQL (prof version only). What about Visual Basic.NET? You can pick up the SDK command line fully functional compiler at the extreme price of zilch - well possibly for the price of the CD. It is only the IDE and a few extras that MS actually charge for.<p>It is freeware.<p>Colin
On a clear disk you can seek forever.
Matt
Posts: 36
Joined: Tue Mar 11, 2003 1:01 am
Location: Bolingbrook,ill. By Chicago
Contact:

Re: VB5 program

Post by Matt »

Will the string be returned in variable format like "firstname&...." or will it be dynamic like "joe&shmoe....." ?
========
--Matt--
========
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: VB5 program

Post by greg123 »

Mike, <p>Totally Possible. Can you provide the complete string, i.e. including all data? <p>Is this sent to you as an email? The hardest part would be to use the VB outlook object module to open the file and read the data. <p>For a text file, it would be easy to read. It is possible that you can save them emails as a text file, or do you have to leave them in outlook?<p>Either way, the LTrim(), RTrim() or Trim() commands can trim the string into sections and place them into a text file as required.<p>
Also, can your hosting service allow ASP or PHP? It might be easier to integrate VB with forms generated by the above.<p>greg
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: VB5 program

Post by greg123 »

Another Thought,<p>It is easy for VB to go to a website and read the source code for data. Thus, if you had your mailer form return an appending text file, the VB script could go to the site (every specified interval) and read the data and present it in a form for you.<p>The coding for this is rather easy. You will have to learn how to use class headers and NOBR items in HTML though. I can help with this if you want.<p>Also, why can't your form just return the data as:<p>First : Greg
Last: Davis .........<p>Then save this appending on the site as a text file. If you save it with a record number that auto increments, i.e.<p>Rec 1
First : Greg
Last: Davis .........<p>Rec 2
First : Mike
Last: Smith .........<p>The vb can easily read this and save it to a database (excel or Access) for storage.<p>...Food for thought....<p>
greg
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: VB5 program

Post by Mike »

Greg, the file is a text file named postdata.att. It contains the following:<p>FirstName=John&LastName=Smith&Address=123+Fake+Street&City=Fake+Town&State=Some+State&ZipCode=12345&eMail=[email protected]&PhoneNumber=%28123%29456-7890&Insurance=checkbox&Submit=Purc hase<p>If you notice, the phone number was entered as (123)456-7890, yet the form turned the ( and ) into %28 and %29. I could make the users enter the data as one string, no spaces or (). Yes, the site supports ASP. In fact, the order page is a javascript ASP. The site is designed as follows:<p>Products page - Each link is view.asp?Item=item&Description=description&Price=$Price&Photo=photos/item#.jpg<p>view.asp opens the picture, displays the info, and makes the link of add to cart link to purchase.asp?Item=Item&Price=$Price
The name, address, etc. form is on that page. The price and item # is stored in a hidden field, and also on the screen. When the user clickes on submit, a script makes sure that the form is filled out, then the form action is Post to mailto:[email protected]?Subject=Order.<p>The Order e-mail sent is blank with the postdata.att file attached.<p>A VB program would be great, but how would the ASP method work?<p>Thanks again, Mike
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: VB5 program

Post by greg123 »

Hey mike, sorry for the delay..<p>Another question. Can you server provide database support. Perhaps a SQL or Access database? <p>The ASP page can write directly into the database and you can then Query the database with a VB app. to extract the data needed.<p>From a sales point of view, the DB is great because you can track all purchases made by a certain customer, all customer a certain item was sold to, etc.....<p>With a relationship database, the possibilities are endless.<p>What is the url of your site? Also, can you send me the code for your ASP so I can get started on the other code?<p>thanks<p>g
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: VB5 program

Post by Mike »

it is at home.1asphost.com/thelodge (doesn't work with a www in it)
I will send you the zip file I used by e-mail with all of the site, except for pictures, in it.<p>-Mike
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: VB5 program

Post by greg123 »

Mike,<p>Try the following, it will remove the data from the string and put it into a msgbox for now. I am still working on the text box's but it should give you an idea.<p>
'***CODE BELOW POST EVERYTHING AND CLICK RUN***<p>Option Explicit<p>Private Function GetData(strTxt As String, tag As String) As String
Dim TagPos As Long
Dim EndPos As Long

GetData = ""
TagPos = InStr(1, strTxt, tag & "=", vbTextCompare)
If (TagPos > 0) Then
EndPos = InStr(TagPos, strTxt, "&")
If (EndPos = 0) Then
GetData = Mid$(strTxt, TagPos + Len(tag) + 1)
Else
GetData = Mid$(strTxt, TagPos + Len(tag) + 1, EndPos - TagPos - Len(tag) - 1)
End If
End If
End Function<p>Private Function FormatString(strTxt As String)
FormatString = Replace(strTxt, "+", " ")
FormatString = Replace(FormatString, "%28", "(")
FormatString = Replace(FormatString, "%29", ")")
' you need to add any more commonly used chars.....
' there might be a better way of doing this function...need to look further into that. but good enough for now.
End Function<p>Sub Form_load()

'You can re-comment below when done. This is just to test.
Const strTxt = "FirstName=John&LastName=Smith&Address=123+Fake+Street&City=Fake+Town&State=Some+State&ZipCode=12345&eMail=[email protected]&PhoneNumber=%28123%29456-7890&Insurance=checkbox&Submit=Pur c hase"<p>'Uncomment below to read from a text file saved on your machine.
' Dim strTxt As String
' Open "postdata.att" For Input As #1
' 'Open App.Path & "\postdata.att" For Input As #1
' Input #1, strTxt
' Close #1

MsgBox FormatString(GetData(strTxt, "FirstName"))
MsgBox FormatString(GetData(strTxt, "LastName"))
MsgBox FormatString(GetData(strTxt, "Address"))
MsgBox FormatString(GetData(strTxt, "City"))
MsgBox FormatString(GetData(strTxt, "State"))
MsgBox FormatString(GetData(strTxt, "ZipCode"))
MsgBox FormatString(GetData(strTxt, "email"))
MsgBox FormatString(GetData(strTxt, "PhoneNumber"))
MsgBox FormatString(GetData(strTxt, "Insurance"))
MsgBox FormatString(GetData(strTxt, "Submit"))<p>End Sub<p>***END CODE***<p>
Try the above. You will have to save your attachments from the email to a file, and then use the VB app to read them.<p>The problem I can see happening is that, if you have multiple orders, you will have multiple emails with multiple attachments with the same name. The vb app will just remove the data and present it into a text box. <p>You will then need to print your form, or copy out the data by hand. If you want to save the data, you can:<p>- Save it to a text file. This will be a huge mess and not practical.<p>- Save the data to an excel workbook. It would save First Name to col A, Last to Col B and so on. More practical. Difficult to implement with VB but can be done.<p>- Save to Access database. As mentioned before, best option. VB, not so difficult to implement. You can then create forms to query your saved data, add more data (shipping bill numbers....) to other tables and have a relationship between your tables. All can be done in VB.<p>I can code the top three options.<p>Also, you can set up your ASP script to save directly to a database. Is this a possibility? Then you can have your VB app do a daily query on new sales for the day, and print a report with the important information. Then you do not need to go through the email, la la la.......<p>
greg
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: VB5 program

Post by greg123 »

Mike, Here is the finished VB program to read your string and display the data in text boxes.<p>Here is what you need to do:<p>- Start a new form
- Add 10 text boxes (do not change their names)
- Add 10 label (do not change their names)
- Ensure that Label1 is next to Text1
- Add 3 command buttons (do not change their names)
-Copy the following code directly and press run<p>'***CODE BELOW***
'***COPY AFTER THIS***<p>Option Explicit<p>Private Function GetData(strTxt As String, tag As String) As String
Dim TagPos As Long
Dim EndPos As Long

GetData = ""
TagPos = InStr(1, strTxt, tag & "=", vbTextCompare)
If (TagPos > 0) Then
EndPos = InStr(TagPos, strTxt, "&")
If (EndPos = 0) Then
GetData = Mid$(strTxt, TagPos + Len(tag) + 1)
Else
GetData = Mid$(strTxt, TagPos + Len(tag) + 1, EndPos - TagPos - Len(tag) - 1)
End If
End If
End Function<p>Private Function FormatString(strTxt As String)
FormatString = Replace(strTxt, "+", " ")
FormatString = Replace(FormatString, "%28", "(")
FormatString = Replace(FormatString, "%29", ")")
' you need to add any more commonly used chars.....
' there might be a better way of doing this function...need to look further into that. but good enough for now.
End Function
Sub Form_load()

Label1.Caption = "First Name"
Label2.Caption = "Last Name"
Label3.Caption = "Address"
Label4.Caption = "City"
Label5.Caption = "State"
Label6.Caption = "Zipcode"
Label7.Caption = "email"
Label8.Caption = "Phone Number"
Label9.Caption = "Insurance"
Label10.Caption = "Submit"<p>With Command1
.Caption = "Clear Data"
End With<p>With Command2
.Caption = "Write To Database"
End With<p>With Command3
.Caption = "Print Data"
End With<p>'You can re-comment the line below when done. This is just to test.
Const strTxt = "FirstName=John&LastName=Smith&Address=123+Fake+Street&City=Fake+Town&State=Some+State&ZipCode=12345&eMail=[email protected]&PhoneNumber=%28123%29456-7890&Insurance=checkbox&Submit=Pur c hase"<p>'Uncomment below to read from a text file saved on your machine.
'Dim strTxt As String
'Open "postdata.att" For Input As #1
''Open App.Path & "\postdata.att" For Input As #1
'Input #1, strTxt
'Close #1


Text1.Text = FormatString(GetData(strTxt, "FirstName"))
Text2.Text = FormatString(GetData(strTxt, "LastName"))
Text3.Text = FormatString(GetData(strTxt, "Address"))
Text4.Text = FormatString(GetData(strTxt, "City"))
Text5.Text = FormatString(GetData(strTxt, "State"))
Text6.Text = FormatString(GetData(strTxt, "Zipcode"))
Text7.Text = FormatString(GetData(strTxt, "email"))
Text8.Text = FormatString(GetData(strTxt, "PhoneNumber"))
Text9.Text = FormatString(GetData(strTxt, "Insurance"))
Text10.Text = FormatString(GetData(strTxt, "Submit"))<p>End Sub<p>'***Copy END***
'***Code Ends***<p>There ya go!<p>Let me know about the database, it would be a fun project!<p>Greg<p>[ September 24, 2003: Message edited by: Greg ]</p>
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: VB5 program

Post by Mike »

Thanks so much for the help, Greg. I can use a MS Access database on my site. I have to use a DSN-Less connection (described at the hosting companies site, www.1asphost.com ). The thing that worries me about databases is that, according to the site, they aren't secured and somebody could get all the customer data by downloading the file. <p>Thanks again, Mike
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests