VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,427 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,496 people online right now. Registration is fast and FREE... Join Now!




Again Same problem

 

Again Same problem

kayatri

30 Jun, 2009 - 11:56 PM
Post #1

D.I.C Head
**

Joined: 5 May, 2009
Posts: 178


My Contributions
Hai,

I have a lines in my text file like this

x y
x Y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y

let say i have 20 lines like this.

I want to change this lines according to user input. So user will input how many lines they want to change in terms of row and column.
in my program Row=TextBox5.Text column=TextBox6.text

user must enter initial value for x and y. Let say the initial value is x=1 y=1.
Row=2 column=5.. now my lines should look like this.

1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
x y
x y
x y
x y
x y
x y
x y
x y
x y
x y

since i enter row=2 only two set of lines is change other lines remain unchange.
but in my coding all the lines is changing like this


1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
1 3
2 3
3 3
4 3
5 3
1 4
2 4
3 4
4 4
5 5
which is wrong.

this is my code

CODE
Dim lines() As String = IO.File.ReadAllLines("C:\wirematches.txt")
        Dim xValue As Decimal = Val(TextBox1.Text)
        Dim yValue As Decimal = Val(TextBox2.Text)
        Dim altValue As Decimal = 2.54
        Dim lineTracker As Integer = 0
        Dim aX As Decimal

        For lineNumber As Integer = 0 To lines.GetUpperBound(0)
If lineTracker = 0 Then
                aX = xValue
                x = aX.ToString("0.00")
                y= yValue.ToString("0.00")
            ElseIf (lineTracker = Val(TextBox6.Text)) Then
                aX = xValue
                yValue = yValue + altValue
                x = aX.ToString("0.00")
                y = yValue.ToString("0.00")
            ElseIf lineTracker > 0 And lineTracker < Val(TextBox6.Text) Then
                aX = aX + altValue
                x = (aX).ToString("0.00")
                y = (yValue).ToString("0.00")

            End If
            If lineTracker < Val(TextBox6.Text) Then
                lineTracker += 1

            Else
                lineTracker = 1
            End If
Next


        IO.File.WriteAllLines("C:\wirematchesout.txt", lines)



this code working fine for changes the column. But i dont know where i should write the code for row. Can any one help me


User is offlineProfile CardPM
+Quote Post


CamoDeveloper

RE: Again Same Problem

1 Jul, 2009 - 11:20 AM
Post #2

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
Well in that For...Next loop you're telling it to loop through for all the lines in the text file. You need to do it for the length the user inputs. Also, try using a case statement instead of the If...Then's. Try something like:
CODE

For lineNumber As Integer = 0 To Me.TextBox6.Text - 1
            Select Case lineTracker
                Case 0
                    'Code Here
                Case lineTracker = Val(Me.TextBox6.Text)
                    'Code Here
                Case lineTracker > 0 And lineTracker < Val(TextBox6.Text)
                    'Code Here
            End Select
            If lineTracker < Me.TextBox6.Text Then
                lineTracker += 1
            Else
                lineTracker = 1
            End If
        Next


Hope this helps.

~Camo
User is offlineProfile CardPM
+Quote Post

kayatri

RE: Again Same Problem

1 Jul, 2009 - 05:46 PM
Post #3

D.I.C Head
**

Joined: 5 May, 2009
Posts: 178


My Contributions
Thanx for your reply. But the TextBox6.text value is for determine how many lines should change out of all the lines. and the TextBox5.Text should determine for how many times the patern should occur. For example my TextBox values are like this

TextBox5.text=2 TextBox6.text=10

so it should works like this. For every 10 lines the patern should changes. But the patern should chages for 2 times only because TextBox5.text=2, it means only 20 lines which is two sets of line should change and others remain unchange..

I dont know where i should put my TextBox5.text value. Can you help me?
User is offlineProfile CardPM
+Quote Post

CamoDeveloper

RE: Again Same Problem

1 Jul, 2009 - 08:08 PM
Post #4

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
Oh, I misunderstood the question, my bad. So it would look some thing like this if done correctly?
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
10 2

That would be 20 lines with the pattern changing twice. Is that correct or am I missing it still?

~Camo
User is offlineProfile CardPM
+Quote Post

kayatri

RE: Again Same Problem

1 Jul, 2009 - 09:09 PM
Post #5

D.I.C Head
**

Joined: 5 May, 2009
Posts: 178


My Contributions
QUOTE(CamoDeveloper @ 1 Jul, 2009 - 08:08 PM) *

Oh, I misunderstood the question, my bad. So it would look some thing like this if done correctly?
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
10 2

That would be 20 lines with the pattern changing twice. Is that correct or am I missing it still?

~Camo



Ya its correct. I try so many times ready to solve this problem but can not.. Can you help me
User is offlineProfile CardPM
+Quote Post

CamoDeveloper

RE: Again Same Problem

1 Jul, 2009 - 10:41 PM
Post #6

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
I can't test the code, so I don't know if this will work. But try something like this
CODE

For lineNumber As Integer = 0 To lines.GetUpperBound(0)
  Select Case lineTracker
    Case 0
      aX = xValue
      x = aX.ToString("0.00")
      y= yValue.ToString("0.00")
    Case lineTracker = Val(Me.TextBox6.Text)
      aX = xValue
      yValue = yValue + altValue
      x = aX.ToString("0.00")
      y = yValue.ToString("0.00")
    Case lineTracker > 0 And lineTracker < Val(Me.TextBox6.Text)
      aX = aX + altValue
      x = (aX).ToString("0.00")
      y = (yValue).ToString("0.00")
  End Select
  
  If x >= Val(TextBox5.Text) Then
    x = 1
  End If
  If lineTracker < Val(TextBox6.Text) Then
    lineTracker += 1
  Else
    lineTracker = 1
  End If
Next


~Camo
User is offlineProfile CardPM
+Quote Post

kayatri

RE: Again Same Problem

2 Jul, 2009 - 05:07 PM
Post #7

D.I.C Head
**

Joined: 5 May, 2009
Posts: 178


My Contributions
QUOTE(CamoDeveloper @ 1 Jul, 2009 - 10:41 PM) *

I can't test the code, so I don't know if this will work. But try something like this
CODE

For lineNumber As Integer = 0 To lines.GetUpperBound(0)
  Select Case lineTracker
    Case 0
      aX = xValue
      x = aX.ToString("0.00")
      y= yValue.ToString("0.00")
    Case lineTracker = Val(Me.TextBox6.Text)
      aX = xValue
      yValue = yValue + altValue
      x = aX.ToString("0.00")
      y = yValue.ToString("0.00")
    Case lineTracker > 0 And lineTracker < Val(Me.TextBox6.Text)
      aX = aX + altValue
      x = (aX).ToString("0.00")
      y = (yValue).ToString("0.00")
  End Select
  
  If x >= Val(TextBox5.Text) Then
    x = 1
  End If
  If lineTracker < Val(TextBox6.Text) Then
    lineTracker += 1
  Else
    lineTracker = 1
  End If
Next


~Camo



I tried your code Camo but it not gave me the ouput i want.. I dont know how i should modify the code and make it work?
User is offlineProfile CardPM
+Quote Post

eker676

RE: Again Same Problem

2 Jul, 2009 - 07:29 PM
Post #8

C++ Programmer
Group Icon

Joined: 18 Apr, 2009
Posts: 652



Thanked: 68 times
Dream Kudos: 25
My Contributions
Debug the code and find where it makes the unwanted changes and then fix is accordingly.

If you don't know how to debug your code, click on the gray array to the left of your code (in the margin) and place a break point and then hit debug and step through the code.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:24AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month