|
-
October 25th, 2011, 06:21 AM
#1
padding
hi
need to pad a few fields been pulled from a database
[code language="VB.NET"]Private Function ReadQueryResults() As Boolean
On Error GoTo ReadQueryResults_Error
Dim sOut As String
Dim j As Integer
Close #17
Open OPXCOM$ + "\SNEX.TXT" For Input As #17
Do While Not (EOF(17))
For i% = 1 To UBound(QU_ARRAY$)
Input #17, QU_ARRAY$(i%)
Next i%
SNEX_ARRAY$(EXE_DESCRIPTION) = "DESCRIPTION"
SNEX_ARRAY$(EXE_AMOUNT) = QU_ARRAY$(QU_AMCLSGPRME)
sOut = ""
For j = 1 To UBound(SNEX_ARRAY$)
sOut = sOut & SNEX_ARRAY$(j)
Next j
Loop
Close #17
ReadQueryResults_Exit:
Exit Function
ReadQueryResults_Error:
ErrorRoutine$ = "ReadQueryResults"
Gerr Err
End Function[/code]
never done this before has anyone any ideas how to do this
thanks
-
October 25th, 2011, 07:57 AM
#2
Re: padding
Well first it looks like you are pulling data from a file rather than a database. Second it also says you are using VB.Net rather than VB6 but the code looks like VB6. Third you did not say if you want to right pad or left pad the data nor what you want to pad with.
One way to padd a string in VB is to use the String() and Right() or Left() functions.
For example you can right pad using code something like this.
Code:
NewString=Left$(OldString & String$(MaxLen,PadChar),MaxLen)
btw I would advise using a variable and the FreeFile function rather than a hard coded file number.
Always use [code][/code] tags when posting code.
-
October 26th, 2011, 04:18 AM
#3
Re: padding
this works to right pad it
SNEX_ARRAY$(EXE_DESCRIPTION) = QU_ARRAY$(QU_GLNO)
SNEX_ARRAY$(EXE_DESCRIPTION) = Space(24 - PadRight(SNEX_ARRAY$(EXE_DESCRIPTION))) & SNEX_ARRAY$(EXE_DESCRIPTION)
how do i get it to left pad
-
October 26th, 2011, 08:37 AM
#4
Re: padding
You just reverse it. The string goes first and then the space. I don't know vbnet so I am unfamiliar with PadRight, but it is not needed. I'll use len for the length of the string.
SNEX_ARRAY$(EXE_DESCRIPTION) = SNEX_ARRAY$(EXE_DESCRIPTION) & Space(24 - len(SNEX_ARRAY$(EXE_DESCRIPTION)))
-
October 26th, 2011, 09:52 AM
#5
Re: padding
Code:
NewString=Right$(String$(MaxLen,PadChar) & OldString ,MaxLen)
The advantage to this method is that it allows you to pad with any character rather than being limited to spaces.
Always use [code][/code] tags when posting code.
-
October 26th, 2011, 10:50 AM
#6
Re: padding
You can also use Rset() and Lset()
Code:
Option Explicit
Private Sub Form_Load()
Dim str(247) As String * 10
Dim strOut As String
Dim x As Integer, dt As Date
dt = #8:00:00 AM#
For x = 0 To 47
str(x) = Space(8)
Next x
' Open "c:\temp\schedule.txt" For Output As #1
For x = 0 To 47
If x Mod 2 = 0 Then
RSet str(x) = Format(dt, "HH:MM AMPM")
Else
RSet str(x) = Format(dt, ":n") & " "
End If
strOut = str(x) ' & vbCrLf
' Print #1, strOut
Debug.Print strOut
dt = DateAdd("n", 30, dt)
Next x
' Close #1
Unload Me
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|