Jump to content
Sign in to follow this  
Guest Andrew

Visual Basic Geeks -I need help

Recommended Posts

Guest Andrew

Writing some software at work -

It basically converts a comma delimited file to a simple HTML table -

but in VB6 the farking Print command does a newline each time it runs - which is creating a very ugly table.

Option Explicit

Private Sub Form_Load()
    
    'Dimension Variables Needed
    Dim str_comma As String
    Dim strcomparing As String
    Dim int1 As Integer
    Dim firstrun As Boolean
    Dim x As Long
    Dim sTemp As String
    
    'Set varible value
    firstrun = True
    str_comma = ","
    
    'Open files for read and write
    Open App.Path & "\premiumstock.html" For Output As #1
    Open App.Path & "\stock.csv" For Input As #2
    
    While Not EOF(2)
        Line Input #2, sTemp
        
            If firstrun = True Then
                Print #1, "<font face=""Tahoma"" size=""1"">"
                Print #1, "<div align=""right""> <table border=""1"" cellspacing=""1"">" 'width=""100%""
                Print #1, "<tr>"
            Else
                Print #1, "</tr> <tr>"
            End If
        Print #1, "<td width=""7.14%"">"
        
        For x = 1 To Len(sTemp)
            strcomparing = Mid$(sTemp, x, 1)
            int1 = StrComp(strcomparing, str_comma, 1)
            
            If strcomparing <> str_comma Then
                Print #1, strcomparing
            End If
            
            If int1 = 0 Then
                Print #1, "</td>"
                Print #1, "<td>"
            End If
            
            firstrun = False 'change condition to end tables correctly
        Next
    Wend
    Print #1, "</tr>"
    
    Close #1
    Close #2
    
    End
    
End Sub

Suggestions?

Share this post


Link to post
Share on other sites

When you go through the loop dont print each 'field' to your html, concatenate them to a temp string.

Once your loop has finished concatenating each field print the line out in one go.

Share this post


Link to post
Share on other sites
Guest Andrew

When you go through the loop dont print each 'field' to your html, concatenate them to a temp string.

Once your loop has finished concatenating each field print the line out in one go.

cheers - will give that ago.

I'm finding VBs text handling extremely poor compared to python or C. Now that I look back on it - I could of done this in python even hah.

syntax for concat in VB?

Share this post


Link to post
Share on other sites
Guest Andrew

For all of you

it is generating code like

<p align="center"><img border="0" src="PWA_logo_2col.jpg" width="640" height="172"></p>
<html>
<head>
<title>Premium Wholesale Auctions LTD - Dealer Wholesale List. Updated 21/10/2005</title>
</head>
<body>
<font face="Tahoma" size="1">
<div align="right"> <table border="1" cellspacing="1">
<tr>
<td width="7.14%">
S
t
o
c
k
</td>
<td>
Y
e
a
r
</td>

<td>
C

etc

Share this post


Link to post
Share on other sites
Guest Andrew

Martyn - found an easier solution.

Occured to be as I was skiiming through a tutorial on OLD OLD BASIC

Print does not add extra delimiters, but does concatenate a final CR/LF to each line. The CR/LF can be suppressed by ending the command with a semicolon (;). (This trick has been available in every Basic I've used, but it is not documented in the VB 6.0 Help.) Read it back with Line Input. (Line Input assumes a DOS type ASCII input file where each line is terminated with CR/LF. It does not recognize the unix line termination character.)

BADASS - good old semicolon saved the day.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...