Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a word in Notepad in a specific location

Status
Not open for further replies.

diarratech

Technical User
Jul 7, 2000
41
FR
Let's say I have a format in Notepad like the following:

Programming Skills Name

Visual Basic 10

Java Steve Johnson

Is it possibe to insert info from VB(textboxes for instance) to fill the missing info? Also, the word should not have any quotations.
Thanks
 
Not that I'm aware of. Opening the file in Binary will allow you to output data at specific locations within the file, but it will overwrite data instead of inserting it. I believe you may need to manipulate this information programatically. Any other ideas?

-Mike Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Here's something to think about.

Dim sLine as String
Open sFileName For Input As #1
Open sFileNew For Output As #2
Input #1, sLine
Mid$(sLine, 63, 9) = “Your Name”
Print #2, sLine
Do While Not EOF(1)
Input #1, sLine
If left(sline,10) = “Visual Basic” then
Mid$(sLine, 63, 9) = “Your Name”
endif
Print #2, sLine
Loop
Close #1, #2

This reads one file and duplicates it with the added text.
RKA:)
 
I don't think that will work in the case where the name is filled but the skills are blank. Assigning values to the middle of a string in this way will still overwrite the information (at least in my testing just now). If there isn't a specific reason to use tabs in the file to separate the data, then I recommend using commas or semicolons. That way you can use the Split function to return an array of values:

Private Sub Command1_Click()
Dim strTest As String
Dim res() As String

strTest = "Language;Skills;Name"

res = Split(strTest, ";")

MsgBox res(0) & vbTab & res(1) & vbTab & res(2)

End Sub

if you have a situation where something is missing from strTest, but the semicolon delimiter is still holding its place, you can still use this:

Private Sub Command1_Click()
Dim strTest As String
Dim res() As String

strTest = "Language;;Name"

res = Split(strTest, ";")

MsgBox res(0) & vbTab & res(1) & vbTab & res(2)

End Sub

In this case res(1) will contain an empty string value. Now it's just a matter of checking wheather each element of the res array has data, if not use the index to determine what data is supposed to be there. Hopefully that will work for u.

-Mike

* as an afterthought, it may be possible to pass vbTab as the delimeter argument to the Split function. If so, then you should be able to use the text format you already have, assuming that tabs are actually present where the information is missing.


Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
The mid function will get characters in the middle of a string or it will place characters in the middle of a string.

a="123456789012314455"
mid(a,6,2) = "RA"
?a
12345RA89012314455

RKA:)
 
This looks like it's going to work. I'm going to play with it. Really, thank both of you very much.
 
RAtkison, you're right. But it looked to me like he needed the function to give this output:

12345RA6789...

I may have misread the origional question, but it looks like he's got what he needs, nonetheless. :)

-Mike Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
... and there is always an approach like:

Code:
Private Sub InsertAt(ByRef strOrig As String, _
                     ByVal intWhere As Integer, _
                     ByVal strInsertion As String)
    strOrig = Left$(strOrig, intWhere - 1) _
            & strInsertion _
            & Mid$(strOrig, intWhere)
End Sub
Private Sub Form_Load()
    Dim myStr As String
    
    myStr = "1234567890"
    Call InsertAt(myStr, 5, "RA")
    Label1.Caption = myStr
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top