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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a File for Viewing 1

Status
Not open for further replies.

rudejohn

IS-IT--Management
Jul 11, 2003
130
US
Sorry for the n00bish question. Still trying to kinda teach myself the language.

My application is a standalone *.exe doing some file manipulation and is creating a text file. At the end of the program, I want to OPEN the text file (not for writing to it... I want to literally open it in a window for the user to view), then exit the application.

All the file open commands I know are for writing to the file, or appending, etc. I've tried Google, MSN, and searching here, but I guess I'm not including the right search parameters. Can anyone clue me in?

TIA,

RJ

************
RudeJohn
************
 
The easiest way to do this, is to place a richtextbox on the form ,and then load the file into it. You can then disable to box, if you only want the user to view this document.

Use:
RichTextBox1.LoadFile myFileName as string

Good luck

BB
 
Okay, so I could show them the text file in a RichTextBox as a part of my application, and hide the form I used to do all the manipulation earlier?

Is there any way to load the text file using Notepad or Wordpad and then close my application altogether? After this application runs once, the user most likely won't need it to run again.

Thanks!

~rj

************
RudeJohn
************
 
If it is a plain text file you can use Notepad to do it.

Notepad can take a command line parameter that is the name of the file to be opened. ie: Notepad.exe c:\myFile.txt

You can use the Shell() function to do it or there are other more involved ways if that doesn't suit you.
 
Shell() is by far the easiest way to open the file IMO
Code:
Shell "Notepad.exe C:\YourDesiredFile.txt", vbNormalFocus
As partially demonstrated by Sheco

Harleyquinn

---------------------------------
For tsunami relief donations
 
Thanks to both of you for your valuable help. I had seen the Shell() function in a few other threads but when I researched in on MSDN I thought for some reason that it wasn't suitable for my purpose. Have a wonderful Friday and enjoy your weekends. :)

~rj

************
RudeJohn
************
 
BiggerBrother,
I have a question about this method for opening the file. Does this method open the file as binary? Or does it open it as a string?

What I am trying to do is open a JPG file in such a way that would allow me to write some text, or other information, into the picture file, and then save the file. I have an easy time opening the file using the "Get" expression, however, when I save the file, using the "Put" expression, the file doubles in size and is not recognized as a JPG file anymore. Any Ideas?

Thanks

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Homersim2600,

The likely reason that your file gets twice as big is that VB uses unicode for strings. I bet if you use the DOS debug command or some other hex editor you will see that every other byte is trash. When you manipulate bianry data in a string, be sure to use the "B" functions. You know, like MidB() and the rest.
 
AHHH! Thanks. I also wanted to point out that I have found a solution to part of my problem. I am posting the code here, which is a variation of what BiggerBrother posted, that would, theoretically, allow a person to edit parts of files. I have tried it with my JPG files, and it works OK to some extent. There is only so much that I can add/change, and the modifications have to be in the correct place, or my JPG will not display. Ok, I am done writing...


Option Explicit
Public FileName As String

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Form_Load()
Text1.OLEDropMode = rtfOLEDropManual
Command1.Caption = "Open"
Command2.Caption = "Save"
End Sub

Private Sub Command1_Click()
' Open
Text1.Text = vbNullString
CD1.ShowOpen
FileName = CD1.FileName
Text1.LoadFile FileName

End Sub

Private Sub Command2_Click()
' Save
If Len(Text1.FileName) Then
Text1.SaveFile Text1.FileName, rtfText
End If
End Sub

Private Sub text1_OLEDragDrop(Data As RichTextLib.DataObject, _
Effect As Long, Button As Integer, Shift As Integer, _
x As Single, y As Single)

' Drag ANY file from the Explorer, or an "Explorer View"
If Data.GetFormat(vbCFFiles) Then
Text1.LoadFile Data.Files(1), rtfText
End If
End Sub


This code requires one RichTextBox, NOTE: For the sake of confusing myself, I have change the name of my RTB to Text1 instead of the longer Richtextbox1; I like to keep myself on my toes :) . Also, you will need 3-command buttons and a common dialog control if you do not want to drag the file into the richTextBox.

Ok, well, I hope this helps somebody...

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
As you have discovered, you can't just "write some text" into a jpeg. A jpeg has a fairly complex and specific data structure
 
Strongm,

You are just the guy I wanted to see this post! :)

Yes! There is all sorts of stuff that I am learning from my trials and errors. I am not familiar, at all, with data structures and the such because most, if not all, of my VB programming has dealt in communications. I have, so far, two tools that I think will halp me to decipher the way this data is inserted into a JPEG file; one is my PHP script that "reads" the EXIF data, and the other is a program called "PhotoStudio" (available through ). I think by working with these two sources, as well as pictures with this EXIF data embedded into them, I will be able to figure out exactly how to create such data in a manner that the original photo is not corrupt.

You have probably seen hex editors, and the such. Well, what I think I need to do now is figure out how I can see what memory location each of the data bytes is located--just like a hex editor where there would be the following style table:

0x0001 ff ee dd cc bb aa ............
0x0002 99 88 77 66 55 44 ............

and so on...

My theory is that since I have the addresses of where each field lies, and I know what kind of data goes into that field(this information provided by my two sources), then I think if I can only figure out the address of each of the bytes of the JPEG file, then I will be able to insert the correct size, and type of data into the correct location inside of the jpeg. any ideas?


Thanks,

LF



"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Yeah, Funny you mention that part of the site. I overlooked it when I downloaded "PhotoStudio". Lastnight I went through and looked at those PDF files; I didn't stay awake for very long. :) Thanks for the input.



LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top