|
-
Sep 9th, 2000, 05:22 PM
#1
Thread Starter
Fanatic Member
How do I make my program to a specified character in a file. Let's say I want it to go to line 15 of the file and to the 40 character!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Sep 9th, 2000, 07:07 PM
#2
Fanatic Member
You need to use a loop, that inputs a line at a time. When uoi have reached the line that you wish to get the character from, then use Mid$() to extract the char from the string.
Code:
Private Sub Form_Load()
MsgBox getChar("e:\test\test.txt", 15, 40)
End Sub
Private Function getChar(strFile As String, lLineNum As Long, lCharNum As Long) As String
Dim lCount As Long
Dim strLine As String
Open strFile For Input As #1
Do
lCount = lCount + 1
'read in as line
Line Input #1, strLine
'of we have hit the right line
If lCount = lLineNum Then
'return the charcter from the position in lCharNum
getChar = Mid$(strLine, lCharNum, 1)
'close
Close #1
'and exit
Exit Function
End If
Loop Until EOF(1)
End Function
Iain, thats with an i by the way!
-
Sep 9th, 2000, 07:29 PM
#3
If you want to set the caret at a position in a textbox then use the following code:
Code:
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Public Sub SelectPos(txtBox As TextBox, Row As Long, Col As Long)
Dim lngPos As Long
If Row < 1 Or Col < 1 Then
MsgBox "The row and column numbers must be 1 or higher", vbCritical
Exit Sub
End If
With txtBox
lngPos = SendMessage(.hwnd, EM_LINEINDEX, Row - 1, 0)
If lngPos > -1 Then
.SelStart = lngPos + Col - 1
End If
End With
End Sub
Just call the SelectPos function in the following manner:
Code:
SelectPos Text1, 15, 40
Good luck!
[Edited by Joacim Andersson on 09-09-2000 at 08:32 PM]
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
|