Hello, I wish to create a document in a word processor with all the formating etc and save it, then I wish to drop this document on to my form in some control or object so it is hidden from the end user then I wish to load the hidden document into a rich text box so that the end user can read the text of the hidden document, I don't wish to load this document into my project using the open dialog control every time the user opens my project or use any load or shell commands, how can I accomplish this task please ?


Cheers MagicBytes

Recommended Answers

All 5 Replies

In the first place, there's no need to drop a document onto your project, form, or whatever. All you need to know is where the location of the file is.

And then you need to establish some process with a command button, a click event (on a form), etc. to call up the desired document.

You're shooting yourself in the foot.

I don't wish to load this document into my project using the open dialog control every time the user opens my project or use any load or shell commands

It is not possible to not load something into memory that you want to load into memory that you want to use. A shell command is the easiest and quickest solution. You could use an API from the SDK. But that would be more difficult.

What are you trying to accomplish, hide yourself from a user who is running a program that blows up the world if it detects a load a shell request from Visual Basic?

Hello and thanks for the reply.

Well here is my problem with the shell command, example below

RichTextBox1.FileName = ("C:\Documents and Settings\UserName\My Documents\MyDocumentFile.rtf")

Now as you well know, every bodies computer has different User Account Names, so how am I suppose to get around this problem ?

For instance I could use some thing like this below...

RichTextBox1.FileName = ("C:\Documents and Settings\" & UserName & "\My Documents\MyDocumentFile.rtf")

This would suit my project better if I knew how to accomplish this task in VB5, because then it wouldn't matter what an end users computer account name is. my project would always find the rich text file in the documents folder on any ones machine.

I hope I explained why I would like to imbed my document file into the form of my project, this way at least the end user can place my projects excutable in any folder on any drive they choose and my project would always come with my doccument file and would not generate any error messages like "FILE NOT FOUND ! ! !" etc.

Plus using an open dialog control would annoy any user if they had to continually look for and load in my document file every time they wanted to run my project, that would be simular to a NAG screen that every one hates when they are testing out shareware or trialware etc.

I am trying to keep my project as USER FRIENDLY as possible to the END USER.

I need to use this document file in my project because it explains useage etc about my project, I have provided a lengthy file explaining many things and it has been different colored text styles and all the font formatting too etc etc etc...

So I hope you have a better understanding to the nature of my project and any ideas and comments will be very helpful.

So if there is a VB5 command that looks up a users account name this would be very helpful also.

Thanks in advance ...

Cheers from MagicBytes :icon_wink:

Now as you well know, every bodies computer has different User Account Names, so how am I suppose to get around this problem ?

' Declaration Section
Public Declare Function GetEnvironmentVariable Lib "Kernel32" _
   Alias "GetEnvironmentVariableA" (ByVal lpName As String, _
   ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Sub cmdFetchEnv_Click()
   On Error GoTo Fetch_ERROR
   Dim lngReturn As Long
   Dim strVar As String
   Dim strBuffer As String * 255 ' Be careful to declare this as written, otherwise you'll get
   ' a runtime error that you will not be able to recover from.
   Dim strMiddle As String
   Dim intPos As Integer
   
   ' The lngReturn value should give the length of the Environment Variable
   ' the txtEnvir variable should filled in with "USERPROFILE" for your purpose
   ' but can be replaced with any Environment Variable: TEMP, OS, PATH, etc.
   lngReturn = GetEnvironmentVariable(txtEnvir, strBuffer, 255)
   If lngReturn = 0 Then ' An error occured, process it.
      GoTo Fetch_ERROR ' Oh, my soul. A dreaded GOTO statement
   End If
   ' Use the left function to cut off the unwanted null characters
   strVar = Left(strBuffer, lngReturn)
   ' You need to cut out the "\" characters to find the actual user name
   intPos = 1
   While intPos <> 0
      intPos = InStr(1, strVar, "\", vbTextCompare)
      strVar = Right(strVar, Len(strVar) - intPos)
      intPos = InStr(1, strVar, "\", vbTextCompare)
   Wend
   ' This should be your answer as to the username
   txtEnvResult = strVar
   Exit Sub
Fetch_ERROR:
   Dim LastError As Long
   LastError = Err.LastDllError
   MsgBox "You had an error: Error: #" & CStr(LastError), vbInformation, "Error"
End Sub

Hello, I tried the code you posted and works well, thanks, this will be one way of loading in my Rich Text file.

Once again I would like to thank you very much for taking the time to read my posting and supplying a solution to my problem.

Well done

Cheers from MagicBytes :icon_wink:

"""
RichTextBox1.FileName = ("C:\Documents and Settings\UserName\My Documents\MyDocumentFile.rtf")"""

i thought it
RichTextBox1.LoadFile = ("C:\Documents and Settings\UserName\My Documents\MyDocumentFile.rtf")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.