15,899,679 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Franz Schweizer (Top 22 by date)
Franz Schweizer
6-Jun-22 13:18pm
View
believe it or not, im not even able to get 64k out of it either. in fact, im only able to pass off 2400 bytes before it barks at me with Procedure too large. The other method i had with the coll.Add "1,2,3,4,5,6,7,8" strings actually allowed me to add all the data no problem. So I may have to work with that. For that, I need to somehow be able to use Split method and be able to build an array out of that but not even sure if that will also not bark at me too.
Franz Schweizer
6-Jun-22 2:55am
View
thanks. i have some work to do to think about how to go about getting this done, might have to take a crash course on VBA
Franz Schweizer
5-Jun-22 17:17pm
View
well i got an update. i tried adding all the data using this method and it came back with Procedure too large. the only method that actually seemed to allow me to copy all the data was using the string method with the arraylist initially.
Franz Schweizer
5-Jun-22 14:15pm
View
the issue is the function has this whole stream crap involved which you can see it saves this stream. its complicated. tried removing that and just writing it but the data is incorrect
Franz Schweizer
5-Jun-22 14:02pm
View
i agree. i have been trying to append as you are mentioning, to open and close. i know i can append to a text file since this works here. just trying to re-write this crazy WriteBinary function but you have helped tremendously.
Sub VBA_to_append_existing_text_file()
Dim strFile_Path As String
strFile_Path = "C:\test.txt"
Open strFile_Path For Append As #1
Write #1, "This is my sample text"
Close #1
End Sub
Franz Schweizer
5-Jun-22 13:10pm
View
after doing research, you're just missing 'New' in front of Collection but that does work, but as expected, it only writes the 2nd part. I did further digging and found this Collection to Array function which seems to work perfectly fine but when I try to print or pass this array off to WriteBinary, i get a type mismatch:
Public Function CollectionToArr(myCol As Collection) As Variant
Dim result As Variant
Dim cnt As Long
If myCol.Count = 0 Then
CollectionToArr = Array()
Exit Function
End If
ReDim result(myCol.Count - 1)
For cnt = 0 To myCol.Count - 1
result(cnt) = myCol(cnt + 1)
Next cnt
CollectionToArr = result
End Function
Sub Main()
Dim buf As Variant
Dim buffer As New Collection
buffer.Add Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
buffer.Add Array(16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)
buf = CollectionToArr(buffer)
'For Each buf In buffer
'WriteBinary "C:\file.bin", buf
'Next
' For printing arrays as Variants
'PrintArrayToImmediate buf
WriteBinary "C:\file.bin", buf
End Sub
Franz Schweizer
5-Jun-22 3:02am
View
Well I can tell you right off the bat without testing it that it will overwrite the file with each write. It will not append to the file. That's the issue I am facing. Also i just tried this and it threw an error "Object variable or With block variable not set"
Franz Schweizer
4-Jun-22 22:13pm
View
that explains it all, yes
Franz Schweizer
4-Jun-22 21:59pm
View
Deleted
i can't pass 100,000 arguments to an Array so I came across a method to at least be able to create strings of all my byte code initially, and then later be able to process that using Split to create an array but i can see it is not coming as easy as expected and I have programming background in C, C++ and assembly but this one isn't a very "normal" language to begin with.
Franz Schweizer
4-Jun-22 21:54pm
View
Well, WriteBinary is designed to just take buf = Array(77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0, 255, 255, 0, 0, 184, 0, 0, 0, 0, 0...) but cannot use 100,000 arguments. Any other ideas?
Franz Schweizer
4-Jun-22 21:47pm
View
Sorry i am new to this forum, i realized i did not reply to you. Basically, my goal is pretty simple. Create a binary file out of byte code. All those numbers are just decimal format of byte code of a file. It can't come from an external source, but must remain internal. So actually I have created an arrayList of strings because it was the only way to actually get the data into the window without Word crashing. 1700 lines each of 30 decimal numbers delimited by a comma. Basically I need to convert the entire array of strings to one large single dimension array. So
coll.Add "77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0, 255, 255, 0, 0, 184, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
coll.Add "1700 lines"
...
...
Need to convert to buf = Array(77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0, 255, 255, 0, 0, 184, 0, 0, 0, 0, 0, 0........ 100,000 bytes) or re-write the WriteBinary function to accept my arrayList and be able to process each element separately rather than each element as 30 numbers. Does that make sense?
Franz Schweizer
4-Jun-22 21:32pm
View
any ideas?
Franz Schweizer
3-Jun-22 0:56am
View
Deleted
Those bytes are just arbitrary. Im basically creating a data file out of byte code. That is the end goal. Right now my 2nd code, each addition is an entire element of the array. The entire string for example is buf(0), but in my original, only the first byte is the first element. How do I get my strings to collapse into single elements in this array? Once I get that figured out, WriteBinary will be able to do its job. The .txt is also arbitrary. In reality, it is actually a real data file, such as a .bin or .exe
Franz Schweizer
2-Jun-22 2:56am
View
Patrice, there is no offending code. You can try to use any byte code you please. Try using a 100,000 byte array, it will not let you compile for some reason.
Franz Schweizer
2-Jun-22 0:47am
View
Exactly, Dave. Yes. I am not able to use more than 24 of those line separators and I have an enormous amount of values to enter and I'm just not sure how to go about doing this. If I could somehow append to the file, then I could call my function about a thousand times but if not, I'm not sure what else I could do. This VBA language is very limiting and makes no sense that I can't simply use a long line..
Franz Schweizer
1-Jun-22 23:26pm
View
well i did mention everything in my original post? not sure if there was a mis-communication somewhere but my code works perfectly fine. its just the native use of any long lines in VBA throws a syntax error. its simply too long of a line, no matter what. and i have a very very long line. is there a way i can convert a string of bytes such as "61, 61, 61, 61, 76, 240..." to a Variant array? I heard about MID, just not sure what to do anymore. i need to basically pass off strings to another function and have it return this large array that i can then pass off to my WriteBinary function.
Franz Schweizer
1-Jun-22 23:05pm
View
i think you may have missed the point here. my function works fine. the issue is that i cannot use a large massive array in vba. it won't compile. i am looking for a way to be able to either create an array without having to use a large one-line array or some other method, perhaps a modification to this function. but all you really did was replace by aBuf with Tmp but without the join, it doesn't quite work.
Franz Schweizer
1-Jun-22 22:56pm
View
I added the bottom half, writing Tmp instead of aBuf but it only wrote 2 bytes of 0xff to the file.
Franz Schweizer
1-Jun-22 22:36pm
View
not able to use this function at all. missing half of it to even write to a file. also, even if my function is able to use any amount of buf, in vba, i physically cannot have a huge array. it just doesn't work, throws a compile error. whoever programmed it does not let you use an enormous array or string and i can only use 24 of those line separators which would not be enough. i need either a way to concatenate strings such as
buf = "97,97,97,97"
buf = buf & "77,241,45,54"
buf = buf & ...
and then turn this concatenation into a true Variant array that I can then pass off to my function or some way for me to keep calling the function and it append to the file. My functions works perfectly fine. I just have to bypass these vba limitations with the length of an array. Any ideas?
Franz Schweizer
18-May-22 20:23pm
View
edited
Franz Schweizer
14-Apr-22 14:08pm
View
if my program was buggy, why has it been working fine for the last 3 months as a non-DLL program? ive never experienced that until i am trying to use it as an exported function. it is the only function giving me problems.
Franz Schweizer
14-Apr-22 13:50pm
View
it is still doing the same thing. i am getting output such as this:
''$'\001'
Show More