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

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




Help with Common Dialog using Flexgrid

 
Reply to this topicStart new topic

Help with Common Dialog using Flexgrid, i used common dialogue, flex grid

pau-pau
8 Feb, 2007 - 02:06 AM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2007
Posts: 24


My Contributions
this is a code to input a file and display it in a datagrid

CODE

Private Sub cmdLoad_Click()
    Wrap$ = Chr$(13) + Chr$(10)
    cdlCommon.Filter = "Text files (*.TXT)|*.TXT"
    cdlCommon.ShowOpen
    
    If cdlCommon.FileName <> "" Then
        Open cdlCommon.FileName For Input As #1
        Do Until EOF(1)
            Line Input #1, LineOfText$
            AllText$ = AllText$ & LineOfText$ & Wrap$
        Loop
        txtfile.Text = AllText$
        txtfile.Enabled = True
linecount% = 0
charsInFile% = Len(txtfile.Text)

For i% = 1 To charsInFile%
    letter$ = Mid(txtfile.Text, i%, 1)
    If letter$ = Chr$(13) Then
        linecount% = linecount% + 1
        i% = i% + 1
    End If
Next i%

size = linecount% - 1

Call initialize
        
CleanUp:
        Close #1
    End If
    Exit Sub
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
'column title
    grid.TextArray(0) = "Job ID"
    grid.TextArray(1) = "Arrival Time"
    grid.TextArray(2) = "Job Type"
    grid.TextArray(3) = "Memory Size"
    grid.TextArray(4) = "CPU Burst"
    grid.TextArray(5) = "Waiting Time"
    grid.TextArray(6) = "Turn Around Time"
End Sub

Sub initialize()
Dim i%, temp(100)
For i = 1 To size
      grid.Rows = grid.Rows + 1
Next i
charsInFile% = Len(txtfile.Text)
x = 0
charsInFile% = Len(txtfile.Text)
For i% = 1 To charsInFile%
    letter$ = Mid(txtfile.Text, i%, 1)
    If letter$ = Chr$(60) Then
        temp(x) = Mid(txtfile.Text, i% + 1, 2)
        x = x + 1
    End If
Next i%
y = 1
For x = 1 To size
   grid.TextMatrix(x, 0) = temp(y)
   grid.TextMatrix(x, 4) = temp(y + 1)
   grid.TextMatrix(x, 5) = temp(y + 2)
   grid.TextMatrix(x, 1) = temp(y + 3)
y = y + 4
Next x
End Sub


my input is a textfile:


CODE

<20>
<01><01><04><05>
<02><02><04><06>
<03><03><08><02>
<04><04><16><10>
<05><05><16><10>
<06><01><04><05>
<07><02><04><06>
<08><03><08><02>
<09><04><16><10>
<10><05><16><10>
<11><01><04><05>
<12><02><04><06>
<13><03><08><02>
<14><04><16><10>
<15><05><16><10>
<16><01><04><05>
<17><02><04><06>
<18><03><08><02>
<19><04><16><10>
<20><05><16><10>


the numbers in the textfile should display in my grid when loaded but i get an error with the
CODE
txtfile.text

line...

need help....

EDIT: modified title ~ jayman9
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: Help With Common Dialog Using Flexgrid
8 Feb, 2007 - 03:45 AM
Post #2

 
Group Icon

Joined: 3 Aug, 2006
Posts: 1,790



Thanked: 1 times
Dream Kudos: 755
My Contributions
Ive made some changes to your code. It should work now. I've put comments wherever there were changes.
CODE

Dim size As Integer                     'Size must have scope throughout your form module
                                        'since it is being used in two  different procedures
Private Sub cmdLoad_Click()
    Wrap$ = Chr$(13) + Chr$(10)
    cdlCommon.Filter = "Text files (*.TXT)|*.TXT"
    cdlCommon.ShowOpen
    
    If cdlCommon.FileName <> "" Then
        Open cdlCommon.FileName For Input As #1
        Do Until EOF(1)
            Line Input #1, LineOfText$
            AllText$ = AllText$ & LineOfText$ & Wrap$
        Loop
        txtFile.Text = AllText$
        txtFile.Enabled = True
linecount% = 0
charsinfile% = Len(txtFile.Text)

For i% = 1 To charsinfile%
    letter$ = Mid(txtFile.Text, i%, 1)
    If letter$ = Chr$(13) Then
        linecount% = linecount% + 1
        
        i% = i% + 1
    End If
Next i%

size = linecount% - 1

Call initialize
        
CleanUp:
        Close #1
    End If
    Exit Sub
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
'column title
    grid.TextArray(0) = "Job ID"
    grid.TextArray(1) = "Arrival Time"
    grid.TextArray(2) = "Job Type"
    grid.TextArray(3) = "Memory Size"
    grid.TextArray(4) = "CPU Burst"
    grid.TextArray(5) = "Waiting Time"
    grid.TextArray(6) = "Turn Around Time"
    grid.Cols = 6 'Without this, you'll get an error in last for loop
                  'of the "initialize" procedure saying that the subscript is
End Sub           'out of range

Sub initialize()
Dim i%, temp(100)
For i = 1 To size
      grid.Rows = grid.Rows + 1
Next i
charsinfile% = Len(txtFile.Text)
X = 0
charsinfile% = Len(txtFile.Text)
For i% = 1 To charsinfile%
    letter$ = Mid(txtFile.Text, i%, 1)
    If letter$ = Chr$(60) Then
        temp(X) = Mid(txtFile.Text, i% + 1, 2)
        X = X + 1
    End If
Next i%
Y = 1
For X = 1 To size
   grid.TextMatrix(X, 0) = temp(Y)         'Have you entered non-consecutive numbers for a reason
   grid.TextMatrix(X, 4) = temp(Y + 1)     'I think the arguments should be:
   grid.TextMatrix(X, 5) = temp(Y + 2)     '(x,0), (x,1),(x,2),(x,3) and (x,4).
   grid.TextMatrix(X, 1) = temp(Y + 3)     'It shouldn't make a difference as far
Y = Y + 4                                  'as compiler errors are concerned unless
Next X                                     ' you have set the number of columns correctly
End Sub

Hope it helped smile.gif

This post has been edited by Louisda16th: 8 Feb, 2007 - 03:47 AM
User is offlineProfile CardPM
+Quote Post

pau-pau
RE: Help With Common Dialog Using Flexgrid
8 Feb, 2007 - 04:14 AM
Post #3

New D.I.C Head
*

Joined: 30 Jan, 2007
Posts: 24


My Contributions
CODE

Private Sub cmdLoad_Click()
    Wrap$ = Chr$(13) + Chr$(10)
    cdlCommon.Filter = "Text files (*.TXT)|*.TXT"
    cdlCommon.ShowOpen
    
    If cdlCommon.FileName <> "" Then
        Open cdlCommon.FileName For Input As #1
        Do Until EOF(1)
            Line Input #1, LineOfText$
            AllText$ = AllText$ & LineOfText$ & Wrap$
        Loop
                                [size=7][b]txtFile.Text = AllText$[/b][/size]
        txtFile.Enabled = True
linecount% = 0
charsinfile% = Len(txtFile.Text)

For i% = 1 To charsinfile%
    letter$ = Mid(txtFile.Text, i%, 1)
    If letter$ = Chr$(13) Then
        linecount% = linecount% + 1
        
        i% = i% + 1
    End If
Next i%

size = linecount% - 1

Call initialize
        
CleanUp:
        Close #1
    End If
    Exit Sub
End Sub


@Louisda16th
thanks for the changes on my code...


now I high lighted on where i get my error, its in the "txtFile.Text = AllText$" line

I did not create a textbox on purpose, I placed the txtfile.Text there to try hold the contents of my text file as I get the values placed in the brackets "<16>". I already tried a string to hold the contents of the text file but still nothing happens.

after i open my text file its supposed to display on the grid's rows and columns.

This post has been edited by pau-pau: 8 Feb, 2007 - 04:17 AM
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: Help With Common Dialog Using Flexgrid
8 Feb, 2007 - 04:29 AM
Post #4

 
Group Icon

Joined: 3 Aug, 2006
Posts: 1,790



Thanked: 1 times
Dream Kudos: 755
My Contributions
What error are you talking about? I used a string variable instead of a textbox and it works perfectly.
CODE

Dim size As Integer, txtText As String
Private Sub cmdLoad_Click()
    Wrap$ = Chr$(13) + Chr$(10)
    cdlCommon.Filter = "Text files (*.TXT)|*.TXT"
    cdlCommon.ShowOpen
    
    If cdlCommon.FileName <> "" Then
        Open cdlCommon.FileName For Input As #1
        Do Until EOF(1)
            Line Input #1, LineOfText$
            AllText$ = AllText$ & LineOfText$ & Wrap$
        Loop
        txtText = AllText$
        
linecount% = 0
charsinfile% = Len(txtText)

For i% = 1 To charsinfile%
    letter$ = Mid(txtText, i%, 1)
    If letter$ = Chr$(13) Then
        linecount% = linecount% + 1
        
        i% = i% + 1
    End If
Next i%

size = linecount% - 1

Call initialize
        
CleanUp:
        Close #1
    End If
    Exit Sub
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
'column title
    grid.Rows = 4
    grid.TextArray(0) = "Job ID"
    grid.TextArray(1) = "Arrival Time"
    grid.TextArray(2) = "Job Type"
    grid.TextArray(3) = "Memory Size"
    grid.TextArray(4) = "CPU Burst"
    grid.TextArray(5) = "Waiting Time"
    grid.TextArray(6) = "Turn Around Time"
    grid.Cols = 6
End Sub

Sub initialize()
Dim i%, temp(100)
For i = 1 To size
      grid.Rows = grid.Rows + 1
Next i
charsinfile% = Len(txtText)
X = 0
charsinfile% = Len(txtText)
For i% = 1 To charsinfile%
    letter$ = Mid(txtText, i%, 1)
    If letter$ = Chr$(60) Then
        temp(X) = Mid(txtText, i% + 1, 2)
        X = X + 1
    End If
Next i%
Y = 1
For X = 1 To size
   grid.TextMatrix(X, 0) = temp(Y)
   grid.TextMatrix(X, 4) = temp(Y + 1)
   grid.TextMatrix(X, 5) = temp(Y + 2)
   grid.TextMatrix(X, 1) = temp(Y + 3)
Y = Y + 4
Next X
End Sub

User is offlineProfile CardPM
+Quote Post

pau-pau
RE: Help With Common Dialog Using Flexgrid
8 Feb, 2007 - 04:38 AM
Post #5

New D.I.C Head
*

Joined: 30 Jan, 2007
Posts: 24


My Contributions
@Louisda16th

sorry,

It was my mistake,

I forgot to change all the succeding declarations controlled by the variable txtText


thanks a lot...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:35PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month