|
-
Jun 23rd, 2006, 07:31 AM
#1
Thread Starter
Member
-
Jun 23rd, 2006, 07:45 AM
#2
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
Yes you can.. loading the resource file is a byte array...
I added a text file as a custom type and left it default names.. so its 101 in the "CUSTOM" section....
VB Code:
Private Sub Command1_Click()
Dim DNR() As Byte
DNR = LoadResData(101, "CUSTOM")
For x = 0 To UBound(DNR)
Text1 = Text1 & Chr(DNR(x))
Next
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 23rd, 2006, 07:56 AM
#3
Thread Starter
Member
Thnx
Thank You That Exactly What I Want !
-
Jun 23rd, 2006, 12:05 PM
#4
Thread Starter
Member
Forget To Mention ..
I Forget To Mention That I Used
ChrB() Function Instead Of Chr() Function Beacuse
The Last One [Chr()] Does Not Work Corectly !
Thnx
-
Jun 23rd, 2006, 01:42 PM
#5
Lively Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
avoid large numbers of string concentrations. especially when this causes a control to repaint and fire events each time. use a temp string for the concentration. in this case StrConv() should be the fastest way.
replace
VB Code:
For x = 0 To UBound(DNR)
Text1 = Text1 & Chr(DNR(x))
Next
with
VB Code:
Text1 = StrConv(DNR,vbUnicode)
-
Jun 23rd, 2006, 03:52 PM
#6
Thread Starter
Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
You're Right Angilaz In Case Of TextBox Direct Using
But ..In The Case Of Using StrConv() Function Directly ..
It Seems That It Does NOT Work With Me !
Here Is The Code That I Use It ..
Private Sub Command1_Click()
Dim B() As Byte
Dim S As String, I As Long
B = LoadResData(102, "TEXTFILE")
For I = 0 To UBound(B)
S = S & ChrB(B(I))
Next I
Text1 = S
End Sub
It's Work Fine And The Most Important Thing Is
Using ChrB() Function NOT Chr() !
Thank You For You Reply Post !
-
Jun 23rd, 2006, 04:40 PM
#7
Thread Starter
Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Director
Also I Use This Function :
Code:
Option Explicit
Private Sub Command1_Click()
Text1 = ReadResTextFile(103, "TEXTFILE")
End Sub
Function ReadResTextFile(ID As Long, Optional Folder As String = "CUSTOM") As String
'****************************************************************
' Name : ReadResTextFile
' Date : 2006-06-24
' Type : Function
' By : Muhammed_KSA [Muhammed Al Ansari]
'****************************************************************
' This Function Is To Read Any TextFile Directly [*.txt;*.CSV;..]
' From Resource File !
'****************************************************************
'Declaration
Dim B() As Byte
Dim I As Long
Dim BufferText As String
'Definition
B = LoadResData(ID, Folder)
For I = 0 To UBound(B)
BufferText = BufferText & StrConv(ChrB(B(I)), vbUnicode)
Next I
ReadResTextFile = BufferText
End Function
-
Jun 24th, 2006, 04:33 AM
#8
Thread Starter
Member
GIF Or JPG
I Want A Code But This Time Is To Show The JPG Directly
On PictureBox ?
-
Jun 24th, 2006, 05:19 AM
#9
Lively Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
there's a good solution on Planet Source Code:
Planet Source Code
-
Jun 24th, 2006, 07:02 AM
#10
Re: GIF Or JPG
 Originally Posted by Muahmed_KSA
I Want A Code But This Time Is To Show The JPG Directly
On PictureBox ?
You can extract a jpg from a resource file but you have to store it in a temp.jpg to show it. Load a jpg as a Custom and give it a JPG name and a number, in this case its 101.
VB Code:
Option Explicit
Dim Ap As String
Dim ResFile As String
Private Sub Form_Load()
Dim bArr() As Byte
Dim FileNum As Integer
If Right$(App.Path, 1) = "\" Then
Ap = App.Path
Else
Ap = App.Path & "\"
End If
ResFile = Ap & "Temp.jpg"
FileNum = FreeFile()
Open ResFile For Binary As #FileNum
bArr = LoadResData(101, "JPG") 'change this to reflect the correct ID
Put #FileNum, , bArr
Close #FileNum
Picture1.Picture = LoadPicture(ResFile)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Kill ResFile
End
End Sub
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jun 24th, 2006, 01:59 PM
#11
Thread Starter
Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
This Is Good Example And Can Be Used For Any File Type
But I Want A Way That NOT Use Tem File At All..
As I Do With TextFile !
Can You Help ?
-
Jun 24th, 2006, 04:26 PM
#12
Thread Starter
Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
The Link On Planet Source Code Moved To This Link ..
http://www.planet-source-code.com/vb...29004&lngWId=1
Thank You Agilaz !
-
Jun 24th, 2006, 05:01 PM
#13
PowerPoster
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Director
Did you get it .. i just got it to work by appending an image to my EXE then extracting it when the EXE is loaded .. it doesnt require any file ..
-
Jun 24th, 2006, 05:16 PM
#14
PowerPoster
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Director
Here it is .. modified from the link you sent and some code i found elsewhere.
You will need to compile both the AppendImage project and the prjImage Project .. prjImage makes an exe called Test.exe .. this is the main program.
Once that is done .. click the Append_Image.exe and that will add the image "garbage.jpg" to the Test.exe file ..
Now you can copy test.exe anywhere and it will load the image from itself ..
Note that you can add multiple files to the exe .. and extract them all either in this method or just extract to files somewhere else .. Im working on compressing files added now ..
Rory
Last edited by rory; Jun 24th, 2006 at 05:25 PM.
-
Jun 24th, 2006, 06:04 PM
#15
Thread Starter
Member
Re: Q : How Can I Read TextFile From *.Res Without Save It Temporaly In Some Directory ?
I Developed A Class To Read Images & TextFiles From Resorce File
Without Save It A Temporary File [Which Could Cause Some Error Some Times]
VB Code:
'****************************************************************
' Name : CResLoader
' Date : 2006-06-25
' Type : Class
' By : Muhammed Al Ansari
'****************************************************************
'Use Example:
'Private Sub Command1_Click()
'Dim X As New CResLoader
'Text1 = X.ReadResTextFile(103, "TEXTFILE")
'Me.Picture1 = X.ReadImage(101, "JPG")
'End Sub
'****************************************************************
Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As Any) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Function PictureFromByteStream(B() As Byte) As IPicture
Dim LowerBound As Long
Dim ByteCount As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture(15)
Dim istm As stdole.IUnknown
On Error GoTo Err_Init
If UBound(B, 1) < 0 Then
Exit Function
End If
LowerBound = LBound(B)
ByteCount = (UBound(B) - LowerBound) + 1
hMem = GlobalAlloc(&H2, ByteCount)
If hMem <> 0 Then
lpMem = GlobalLock(hMem)
If lpMem <> 0 Then
MoveMemory ByVal lpMem, B(LowerBound), ByteCount
Call GlobalUnlock(hMem)
If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then
If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture(0)) = 0 Then
Call OleLoadPicture(ByVal ObjPtr(istm), ByteCount, 0, IID_IPicture(0), PictureFromByteStream)
End If
End If
End If
End If
Exit Function
Err_Init:
If Err.Number = 9 Then
'Uninitialized array
MsgBox "You must pass a non-empty byte array to this function!"
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Function
Function ReadImage(ID As Long, Optional Folder As String = "CUSTOM") As IPicture
Dim B() As Byte
B = LoadResData(ID, Folder)
Set ReadImage = PictureFromByteStream(B)
End Function
Function ReadResTextFile(ID As Long, Optional Folder As String = "CUSTOM") As String
'****************************************************************
' Name : ReadResTextFile
' Date : 2006-06-24
' Type : Function
' By : Muhammed_KSA [Muhammed Al Ansari]
'****************************************************************
' This Function Is To Read Any TextFile Directly [*.txt;*.CSV;..]
' From Resource File !
'****************************************************************
'Declaration
Dim B() As Byte
Dim I As Long
Dim BufferText As String
'Definition
B = LoadResData(ID, Folder)
For I = 0 To UBound(B)
BufferText = BufferText & StrConv(ChrB(B(I)), vbUnicode)
Next I
ReadResTextFile = BufferText
End Function
Thank You [ALL] For Your Help !
-
Jun 25th, 2006, 02:29 PM
#16
Thread Starter
Member
-
Jun 27th, 2006, 03:25 PM
#17
Thread Starter
Member
Thanks
Thank You All For Your Replies !
Muhamed Al Ansari
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
|