|
Are you serious? Every character that would end up in the result would have been copied six times:
For Each item As Char In TextBox1.Text.ToCharArray
out.Add(item)
outString.Append(item.ToString)
Label1.Text = outString.ToString
BTW: If Not IsNothing(TextBox1.Text) Then is superfluous, TextBox.Text never returns null, when empty (or not explicitly initialized) it returns an empty string, as in ""
|
|
|
|
|
It works, I never said it was efficient! It would have been better just to shift the char straight to the target than through another builder.
When I ran the test this morning, without the line char copy failed when empty. I could have just as easily checked the length (which would have been better).
Anyway, the post is more to get the OP thinking, not necessarily give him the answer on a plate.
|
|
|
|
|
Hmm. I think your If out.Count > 0 Then is superfluous too. When the TextBox looses all its content at once (CTRL/A CTRL/X), the label needs to get cleared. Maybe you needed a coffee shot first...
I still prefer my two-line approach, no list, no SB, no loops.
|
|
|
|
|
|
Write an article on your work, that covers the design, concepts, and coding of your library and you can post that. Just posting a link here isn't going to be well received.
|
|
|
|
|
I have written a code to read a text box character by character and copy the characters into another array. As soon as the space character occurs the process should stop. the Program is giving argument null exception at runtime. Any solutions.
Here is the code.
Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click
Dim objreader As New System.IO.StreamReader(file_name.Text)
TextBox1.Text = objreader.ReadLine
TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf
Dim myArray() As Char
Dim myArray2() As Char
myArray = Me.TextBox1.Text.ToCharArray
For i As Integer = 1 To 70
If myArray(i) <> " " Then
Else
Array.Copy(myArray, myArray2, i)
End If
Next
End Sub
|
|
|
|
|
ArgumentNullException means one of the arguments is null ("Nothing" in your lingo).
Dim myArray2() As Char is not allocating any memory, it only tells the compiler myArray2 is going to refer to some char array, however you (or something you call) needs to pay for the memory (as Me.TextBox1.Text.ToCharArray did for the other array reference). Try the New keyword.
|
|
|
|
|
See the code below, this example using a textbox and a button for the example. The code below is in the button click event;
Dim out As List(Of Char) = New List(Of Char)
If Not IsNothing(TextBox1.Text) Then
For Each item As Char In TextBox1.Text.ToCharArray
If item <> Chr(32) Then
out.Add(item)
Debug.WriteLine(item.ToString)
Else
Debug.WriteLine("Space found......stopping.")
Exit For
End If
Next
End If
If out.Count > 0 Then
Debug.WriteLine("Out Array Contains: " + out.Count.ToString + " items.")
Dim outString As New System.Text.StringBuilder
outString.Append("Out contains: ")
For Each item As Char In out
outString.Append(item.ToString)
Next
Debug.WriteLine(outString.ToString)
Else
Debug.WriteLine("No items in output array")
End If
|
|
|
|
|
Private Sub factuurZoeken_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
m_SelectedStyle = New DataGridViewCellStyle()
m_SelectedStyle.BackColor = Color.LightBlue
m_SelectedStyle.BackColor = SystemColors.Highlight
DataGridView1.ReadOnly = True
Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen"
Dim DataSet As New DataSet()
Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn)
oleConn.Open()
OleDbDataAdapter.Fill(DataSet, "Facturen")
DataGridView1.DataSource = DataSet.Tables("Facturen")
'hier kleuren:
DataGridView1.AutoResizeColumns()
checkfactuurvervallen()
oleConn.Close()
Catch ex As Exception
MessageBox.Show("Fout in Database : " & ex.Message)
oleConn.Close()
End Try
Then my sub factuurvervallen:
Private Sub checkfactuurvervallen()
'kleur records indien vrij of niet(haal datum vandaag op)
Try
Dim vandaag As String = Today
Dim i As Integer = 0
For Each row As DataGridViewRow In DataGridView1.Rows
If DataGridView1.Item(2, i).Value() > vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed
ElseIf DataGridView1.Item(2, i).Value() < vandaag Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
End If
i = i + 1
Next
Catch ex As Exception
MessageBox.Show("Fout in kleuren aangeven : " & ex.Message)
End Try
'tot hier kleuren
End Sub
If i pass the sub factuurvervallen() on a button it colors the rows but in my load after loading the rows it doesn't what am i overseeing??
thx in advance
|
|
|
|
|
I suggest you add a line MessageBox.Show("Tiens, er zijn maar "+DataGridView1.Rows.Count+" rijen in mijn DGV ?!?") inside your checkfactuurvervallen() and then think about the result you are getting.
BTW: Looking at some actual values is the most essential part of debugging.
modified 24-Sep-11 9:46am.
|
|
|
|
|
I have been caught out by this before.
Certain things cannot be done within the Load event because the form has not fully loaded yet.
What I have done as a work around in the past is create a one off timer which is set for 250ms (or suitable time for your needs) and in the tick event call a sub that has the stuff you want to occur at load.
The timer should be long enough to allow the form to display.
Works just fine.
|
|
|
|
|
wouldn't the Shown event be good enough here? I expect all outstanding Windows messages caused inside the Load handler will have been processed by then and the DGV will have been fully populated.
|
|
|
|
|
Probably I forgot all about the Shown event never use to exist before .Net 2, and probably I just got stuck in my ways!
|
|
|
|
|
Hello all!
I am trying to draw two ellipses, both centered on the mouse cursor during a click event.
Currently, I have to offset the X and Y coordinates to do this. This is fine for my first circle, which is of a static size. However, my second circle is variable in size and will always be larger than the first circle.
I am having trouble with this, as I am unable to determine what sort of equation I could use to account for all of the different sizes. Is there a way to have it draw the circle with the cursor position as the center of the circle. Is this at all possible with VB.NET, or am I going to need to start learning C++?
If any code is needed, please let me know and I will provide it.
Thanks in advance!
|
|
|
|
|
ChrisDScott93 wrote: I am unable to determine what sort of equation I could use to account for all of the different sizes.
You have not explained what you are using to determine the size in the first place. Is it something to do with the current mouse position or some sort of offset based on who knows what?
ChrisDScott93 wrote: Is there a way to have it draw the circle with the cursor position as the center of the circle.
I'm sure that is the standard way of drawing a circle; centre it at x y with radius r .
Maybe you need to clarify your problem.
|
|
|
|
|
I am using DrawEllipse to create my circle. This creates a circle within a rectangle and counts the starting position as the top left of the rectangle. It then draws to the right and down to create the circle.
MSDN information for this states: DrawEllipse(Pen, Single, Single, Single, Single) - Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
This is the relevant code:
Dim penCharacterCircle as Pen
Dim gfxCharacterCircle as Graphics
Dim MousePositionX as Integer = Cursor.Position.X - 35
Dim MousePositionY as Integer = Cursor.Position.Y - 55
penCharacterCircle = New Pen(System.Drawing.Color.Green, 6)
gfxCharacterCircle.DrawEllipse(penCharacter, MousePositionX, MousePositionY, 50, 50)
|
|
|
|
|
Assuming that the above is working, I still don't understand what your problem is. Please try and explain exactly what you are trying to do, what results you expect, and what results you see.
|
|
|
|
|
The above draws a circle from the cursor positions, both X and Y coordinates, and then moves the starting point of the circle to the top left by the -35(X) and -55(Y) I used as offsets. This does work properly. What doesn't work are some other circles which are of differing sizes, dependent on a variable.
If I want each secondary circle to be concentric with the first one, I have to manually enter in the values. An example would be: first circle is size 50, second one is 100. When I click, it places the first circle centered around the mouse, equidistant from the clicked point. It then places the second circle. If I don't enter an offset, it places the circle to the bottom right of the clicked point.
I can manually enter an offset so it puts the second circle in the right place, but I have many different sized circles. Each one requires a different offset. This is caused by it drawing the circle from the top left to the bottom right, instead of from the center. It draws it like a rectangle.
I want it to draw the circle from the center, so I don't have to figure out offsets for all of the different sized circles.
|
|
|
|
|
ChrisDScott93 wrote: This is caused by it drawing the circle from the top left to the bottom right, instead of from the center. It draws it like a rectangle.
Yeah, computers are such contrary so-and-sos. Your problem is merely one of mathematics, given the centre and radius of your circle you need to calculate the offset and size of its containing rectangle. If you write a function that does just that then you should be able to draw any size circle at any point in your window. Given that the circle's radius is equal to half the width and height of the rectangle the starting point should be:
Origin = centre.x - Radius, centre.y - Radius
You may also need to adjust for the X:Y ratio unless you are able to set one of the mapping modes which does it automatically (my VB skills are very basic).
|
|
|
|
|
A circle with a center (xc, yc) and radius r1 will span from (xc-r1,yc-r1) to (xc+r1,yc+r1).
And similar formula apply for radius r2.
I can't start to imagine where your problem would be, unless you use Graphics.TranslateTransform and start accumulating those translations.
If you do use those Transform methods in a method, it is wise to also undo the matirx transformations before exiting the method.
modified 24-Sep-11 11:07am.
|
|
|
|
|
I will be honest here, I am just starting out on doing this, and I have not yet become familiar with Graphics.TranslateTransform.
I do not see a way to allow the circle to be created using a radius, but I may just be overlooking something very simple.
Please see my reply to OriginalGriff for a code sample.
|
|
|
|
|
I guess you did not notice that my name is not OriginalGriff!
|
|
|
|
|
Hi not OriginalGriff, how are you today?
|
|
|
|
|
Heh, I saw the link at the bottom of Richard MacCutchan's reply. I was referring to Richard with my comment. Sorry for the confusion!
|
|
|
|
|
I am not OriginalGriff, I am a free man!
|
|
|
|