|
-
Jul 2nd, 2008, 01:01 AM
#1
Thread Starter
Addicted Member
[ask] using space()
i have a function that showing the output from a calculation.
i want to make it looks good on the spacing but i can't do it
help me how to use the space()
Or is there anything to make it in other way
Code:
Private Sub Tampil_Data()
Dim rp As String = "Rp "
kata &= "Project " & k + 1 & vbCrLf
kata &= "======================================================" & vbCrLf
kata &= "year Perkiraan arus kas proyek " & k + 1 & " Arus Kas Kumulatif" & vbCrLf
kata &= "======================================================" & vbCrLf
kata &= Space(1) & "0 (inves)" & Space(5) & rp & Format(inves(k), "#0.00") & Space(48 - ((Format(inves(k), "#0.00")).Length + "0 (inves)".Length)) & rp & Format(inves(k), "#0.00") & vbCrLf
For j = 0 To thn - 1
dataKas(k, j) = inves(k) + data(k, j)
kata &= Space(1) & j + 1 & Space(16 - (Format(j + 1, "0").Length) - 1) & rp & Format(data(k, j), "#0.00") & Space(42 - (Format(data(k, j), "#0.00").ToString.Length + rp.Length + (Format(j + 1, "0").Length) + dataKas(k, j).ToString.Length)) & rp & Format(dataKas(k, j), "#0.00") & vbCrLf
inves(k) = inves(k) + data(k, j)
Next
kata &= "======================================================" & vbCrLf
End Sub
i would like to make the output like this
Code:
year Perkiraan arus kas proyek 1 Arus Kas Kumulatif
0 (inves) Rp -1000.00 Rp -1000.00
1 Rp 500.00 Rp -500.00
2 Rp 400.00 Rp -100.00
3 Rp 10.00 Rp -90.00
4 Rp 5.00 Rp -85.00
5 Rp 1100.00 Rp 1015.00
the problem just how to make the output like that
help me plz
thx
-
Jul 2nd, 2008, 01:44 AM
#2
Re: [ask] using space()
Where exactly is this data being displayed? Is it being output to a file? Displayed in a TextBox? Somewhere else? Regardless, you do NOT want to use Space() at all for anything.
-
Jul 2nd, 2008, 01:45 AM
#3
Re: [ask] using space()
You're being very vague here. What type of project do you have, is it a Windows application? Also, where are you outputting this information to, is it a file? or a textbox on screen? If it's a Windows application and you are outputting this information to screen then you can use a listview (depending upon the version of Visual Studio you are using - you omitted that information also) and configure 3 columns within this control to display data in.
Edit: damn, beaten to it by a single minute!
Last edited by alex_read; Jul 3rd, 2008 at 01:19 AM.
-
Jul 2nd, 2008, 02:28 AM
#4
Re: [ask] using space()
I wouldnt use the MS.VB Space() function but rather the String.PadLeft or String.PadRight funcitons instead. Also, to display evenly spaced text you would need to use a monospaced font like "Courier".
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 2nd, 2008, 11:42 AM
#5
Thread Starter
Addicted Member
Re: [ask] using space()
 Originally Posted by jmcilhinney
Where exactly is this data being displayed? Is it being output to a file? Displayed in a TextBox? Somewhere else? Regardless, you do NOT want to use Space() at all for anything.
the output displays in a textbox
i can't arrange the white space...can u help me..?
so the output like that
thx
-
Jul 2nd, 2008, 11:57 AM
#6
Re: [ask] using space()
if you are trying to line things up using spaces, you need to make sure the font is set to a mono-spaced one (Courier, Lucida).
Also, I'd use a richtextbox, instead of textbox.
Code:
Dim someData As New Random
RichTextBox1.AppendText("Column1".PadRight(10, " "c))
RichTextBox1.AppendText("Column2".PadRight(10, " "c))
RichTextBox1.AppendText(Environment.NewLine)
For x As Integer = 1 To 10
RichTextBox1.AppendText(x.ToString.PadRight(10, " "c))
RichTextBox1.AppendText(someData.Next(11, 100001).ToString.PadLeft(10, " "c))
RichTextBox1.AppendText(Environment.NewLine)
Next
-
Jul 2nd, 2008, 08:50 PM
#7
Re: [ask] using space()
I'd use a ListView rather than a TextBox. It supports columns out-of-the-box.
-
Jul 3rd, 2008, 07:34 AM
#8
Re: [ask] using space()
or you could use listview .
-
Jul 3rd, 2008, 11:58 AM
#9
Re: [ask] using space()
Well I think its in a textbox because the OP may want to print it out this way too. If it was for printing then this is still the wrong way to go about it. One can use a Crystal report, Word, output to pdf etc. all formatted
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 3rd, 2008, 09:56 PM
#10
Thread Starter
Addicted Member
Re: [ask] using space()
i would like to use the textbox....
can anyone help me to arrage like i want...
thx
-
Jul 4th, 2008, 01:36 AM
#11
Re: [ask] using space()
If you really want to ignore our advice and experience, that is upto you and this code is a sample of how you can acheive outputting this to a textbox. However I stress you should still consider and take one of the above-provided, more professional suggestions.
Code:
Public Class Form1
Private Structure TampilDataStructure
Friend Column1Value As String
Friend Column2Value As String
Friend Column3Value As String
End Structure
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
With TextBox1
.Multiline = True
' .Font.Name = "Courier New" - ** SET THIS TEXTBOX PROPERTY MANUALLY **
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Create a list collection of all the values to be entered into the textbox. Note the call to
' the GetSpacedValuesStructure method upon each list item's creation. This will add the/any
' neccessary padding to the string values.
Dim valuesList As New List(Of TampilDataStructure)
With valuesList
.Add(GetSpacedValuesStructure("year", "Perkiraan arus kas proyek 1", "Arus Kas Kumulatif"))
.Add(GetSpacedValuesStructure("0 (inves)", "Rp -1000.00", "Rp -1000.00"))
.Add(GetSpacedValuesStructure("1", "Rp 500.00", "Rp -500.00"))
.Add(GetSpacedValuesStructure("2", "Rp 400.00", "Rp -100.00"))
.Add(GetSpacedValuesStructure("3", "Rp 10.00", "Rp -90.00"))
.Add(GetSpacedValuesStructure("4", "Rp 5.00", "Rp -85.00"))
.Add(GetSpacedValuesStructure("5", "Rp 1100.00", "Rp 1015.00"))
End With
' Iterate through the list collection of values and append each list item's 3 string values
' (with the neccessary padding) to the textbox, followed by a newline character.
For valuesListItemIndex As Integer = 0 To valuesList.Count - 1
With valuesList
TextBox1.AppendText(.Item(valuesListItemIndex).Column1Value)
TextBox1.AppendText(.Item(valuesListItemIndex).Column2Value)
TextBox1.AppendText(.Item(valuesListItemIndex).Column3Value)
TextBox1.AppendText(Environment.NewLine)
End With
Next valuesListItemIndex
End Sub
Private Function GetSpacedValuesStructure(ByVal column1Value As String, _
ByVal column2Value As String, ByVal column3Value As String) As TampilDataStructure
Dim returnTampilDataStructure As TampilDataStructure
Const column1MaxLength As Integer = 12
Const column2MaxLength As Integer = 30
Const column3MaxLength As Integer = 20
If (String.IsNullOrEmpty(column1Value) OrElse String.IsNullOrEmpty(column2Value) _
OrElse String.IsNullOrEmpty(column3Value)) Then
returnTampilDataStructure = Nothing
Throw New ArgumentNullException("Please pass non-empty string arguments " & _
"into the AddSpacedValues method")
Else
returnTampilDataStructure = New TampilDataStructure
If (column1Value.Length < column1MaxLength) Then
returnTampilDataStructure.Column1Value = column1Value.PadRight(column1MaxLength)
ElseIf (column1Value.Length > column1MaxLength) Then
Throw New ArgumentOutOfRangeException(String.Format("Column 1 value '{0}' contains " & _
"more than the expected number of characters. Consider altering the maximum column " & _
"length within the GetSpacedValuesStructure method.", column1Value))
End If
If (column2Value.Length < column2MaxLength) Then
returnTampilDataStructure.Column2Value = column2Value.PadRight(column2MaxLength)
ElseIf (column1Value.Length > column1MaxLength) Then
Throw New ArgumentOutOfRangeException(String.Format("Column 2 value '{0}' contains " & _
"more than the expected number of characters. Consider altering the maximum column " & _
"length within the GetSpacedValuesStructure method.", column2Value))
End If
If (column3Value.Length < column3MaxLength) Then
returnTampilDataStructure.Column3Value = column3Value.PadRight(column3MaxLength)
ElseIf (column1Value.Length > column1MaxLength) Then
Throw New ArgumentOutOfRangeException(String.Format("Column 3 value '{0}' contains " & _
"more than the expected number of characters. Consider altering the maximum column " & _
"length within the GetSpacedValuesStructure method.", column3Value))
End If
End If
Return returnTampilDataStructure
End Function
End Class
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
|