write to file in notepad from combo select

write to file in notepad from combo select

Anonymous
Not applicable
325 Views
4 Replies
Message 1 of 5

write to file in notepad from combo select

Anonymous
Not applicable
Hi,
Just playing with a file compostion program attempt.
objective:
select item in combo box
enter that item at selected location in text file open in notepad
- or open in any other way of viewing a file - like opening in a giant input
box or ???
some way to mimic a notepad like window on a form???

I can fill a combo box from the contents of a text file thusly:

Private Sub PopulateComboBoxFromFile(fname As String, cboObject As ComboBox)
Dim fNum As Integer
fNum = FreeFile
Open fname For Input As #fNum 'Open file for input
Do While Not EOF(fNum) 'Loop until end of file
cboObject.AddItem ReadLineFromFile(ByVal fNum)
Loop
Close #fNum 'Close file
End Sub

Public Function ReadLineFromFile(ByVal fNum As Integer) As String
Dim ThisLine As String
Input #fNum, ThisLine 'Read data into variable
ReadLineFromFile = ThisLine
End Function

Now I open a file in notepad thusly:

Function OpenNotepadTextfile(fullPathName As String) As App ' not sure about
this return type
Dim myappid As Variant
Dim appname As Variant '(1) As Variant
appname = "C:\Windows\notepad.EXE " & fullPathName

myappid = Shell(appname, 1) 'vbMaximizedFocus) ' Run notepad
AppActivate myappid ' Activeate notepad

'now I'm not sure what i want to pass back to the calling sub
'I want to be able to refer to and manipulate this now open file from other
subs
'so I need some reference to it, not sure if this does it for me:
OpenNotepadTextfile = myappid

End Function

'Now I want to be able in some sub to do various things such as:
'''
Function PutFocusInThisFile (ThisFile as fileobject or filename?)as boolean
'get focus on that open file in notepad
PutFocusInThisFile = error-or-not 'return something so I know if theres
problem or not
End Function
'''
Function MoveCursor (ThisFile as fileobject or filename?, ThatDirection as
?, SomeDistance as ?) as boolean
'move cursor in ThisFile by SomeDistance in ThatDirection
MoveCursor = error-or-not 'return something so I know if theres problem or
not
End Function
'''
Function EnterData (sThisFile as Fileobject or filename?, sData as String)
as boolean
'enter string data at current cursor position
EnterData = error-or-not 'return something so I know if theres problem or
not
End Function
'''
is any of this possible or hopefully even easy??? with vb? or do I need to
learn how to do api calls?

Any ideas, help or inspiration appreciated.
Mark
0 Likes
326 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor
>like opening in a giant input
box or ???

How about a RichText control?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable
okay, how about it? :-)~
like I don't know what it is but guess I'll have to dig into the old dox and
find out!
Thanks for the tip
so I guess getting focus into notepad would be mean and dirty and nasty,
yeah?
but rtc is gonna be nice and easy and cool eh?
i hope i hope i hope!

Ed_Jobe wrote in message news:f0ed24e.0@WebX.maYIadrTaRb...
> like opening in a giant input box or ???
>
> How about a RichText control?
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
You could use a text box with the multiline property set to true (to display
and edit your text file). Don't use the rich edit control unless you need
text formatting. I believe the selstart property will return the cursor
position within the text box.

Regards,
Jacob Dinardi


"MP" wrote in message
news:9BC0D718D0DF069096BA7B4AE28F2343@in.WebX.maYIadrTaRb...
> Hi,
> Just playing with a file compostion program attempt.
> objective:
> select item in combo box
> enter that item at selected location in text file open in notepad
> - or open in any other way of viewing a file - like opening in a giant
input
> box or ???
> some way to mimic a notepad like window on a form???
>
> I can fill a combo box from the contents of a text file thusly:
>
> Private Sub PopulateComboBoxFromFile(fname As String, cboObject As
ComboBox)
> Dim fNum As Integer
> fNum = FreeFile
> Open fname For Input As #fNum 'Open file for input
> Do While Not EOF(fNum) 'Loop until end of file
> cboObject.AddItem ReadLineFromFile(ByVal fNum)
> Loop
> Close #fNum 'Close file
> End Sub
>
> Public Function ReadLineFromFile(ByVal fNum As Integer) As String
> Dim ThisLine As String
> Input #fNum, ThisLine 'Read data into variable
> ReadLineFromFile = ThisLine
> End Function
>
> Now I open a file in notepad thusly:
>
> Function OpenNotepadTextfile(fullPathName As String) As App ' not sure
about
> this return type
> Dim myappid As Variant
> Dim appname As Variant '(1) As Variant
> appname = "C:\Windows\notepad.EXE " & fullPathName
>
> myappid = Shell(appname, 1) 'vbMaximizedFocus) ' Run notepad
> AppActivate myappid ' Activeate notepad
>
> 'now I'm not sure what i want to pass back to the calling sub
> 'I want to be able to refer to and manipulate this now open file from
other
> subs
> 'so I need some reference to it, not sure if this does it for me:
> OpenNotepadTextfile = myappid
>
> End Function
>
> 'Now I want to be able in some sub to do various things such as:
> '''
> Function PutFocusInThisFile (ThisFile as fileobject or filename?)as
boolean
> 'get focus on that open file in notepad
> PutFocusInThisFile = error-or-not 'return something so I know if theres
> problem or not
> End Function
> '''
> Function MoveCursor (ThisFile as fileobject or filename?, ThatDirection as
> ?, SomeDistance as ?) as boolean
> 'move cursor in ThisFile by SomeDistance in ThatDirection
> MoveCursor = error-or-not 'return something so I know if theres problem
or
> not
> End Function
> '''
> Function EnterData (sThisFile as Fileobject or filename?, sData as String)
> as boolean
> 'enter string data at current cursor position
> EnterData = error-or-not 'return something so I know if theres problem or
> not
> End Function
> '''
> is any of this possible or hopefully even easy??? with vb? or do I need
to
> learn how to do api calls?
>
> Any ideas, help or inspiration appreciated.
> Mark
>
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanks for the tips, I'll look in that direction

Jacob Dinardi wrote in message
news:B7B84947E844C88AF2CD22D126BC2562@in.WebX.maYIadrTaRb...
> You could use a text box with the multiline property set to true (to
display
> and edit your text file). Don't use the rich edit control unless you need
> text formatting. I believe the selstart property will return the cursor
> position within the text box.
>
> Regards,
> Jacob Dinardi
0 Likes