| Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding |
|
 |
Index ‹ Visual Studio ‹ Visual Basic [VB]
|
- Previous
- 1
- Visual Basic [VB] >> delete file problemi try to print image file in a directory using PrintDocument. It will raise
printPage event to draw image to the printer. The file will be deleted
after print and the directory will be checked every second to get new file
inside it.
Where should i do the delete function? The way to print image is get from
msdn. Can tell me where can i refer to other better ways to print the
image file.
Thank you.
Public fileName As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
Sub printImage(ByVal fileName As String)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
End Sub
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
' Draw a picture.
ev.Graphics.DrawImage(Image.FromFile(fileName),
ev.Graphics.VisibleClipBounds)
' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim dir As New DirectoryInfo("c:\dir")
Dim fi As FileInfo() = dir.GetFiles()
Dim fitemp As FileInfo
For Each fitemp In fi
fileName = fitemp.FullName
printImage(fileName)
Next
End Sub
___
Newsgroups brought to you courtesy of www.dotnetjohn.com
- 2
- MFC >> Windows/MFC bug with TOOLTIPS??I'm not sure if this bug is in MFC or with the tooltip common control, but
I have an MFC application with tooltips enabled for the toolbar. I'm "owner
drawing" the tooltips, but I'm having this problem:
Button1 Button2
the tooltip for Button1 is "AAAAAA"
the tooltip for Button2 is "ZZZZZZZ"
On a "slower" machine (1.6ghz), I mouse over button1 and "AAAAAA" pops up
just fine, then I mouse over button2 and I see "AAAAAA" moved over button2
for a second before it updates itself to "ZZZZZZZ". What I mean, is that I
see the old tooltip moved over to the new location flash before the tooltip
updates.
It even happens on standard tooltips.
Seems like something weird, because if I put a "Sleep(100);" in the WM_PAINT
handler, I can see the window moved over (with the old tooltip intact). Like
windows is caching something. Normally if you put a Sleep(100) in the
WM_PAINT handler and the window is hidden/shown like a tooltip, I would
expect the window underneath to show through, but it doesn't in this case...
the window is shown like its being painted somehow.
I've tried the normal tricks with UpdateWindow(), SetWindowRgn(),
WS_VISIBLE, etc... but I can't figure out a way around this...
Any ideas?
- 3
- Visual Basic >> VB5 Recent MenuI'm using VB5 and I would like to clean the VB5 recent menu.
There are some applications which I have deleted but their names still stay
in the menu.
Is there any way to clear the recent menu? Or maybe remove individual
entrys?
Thanks in advance!
Steven
- 4
- MFC >> Remote Desktop does not show system tray icon.My program is a service that runs on Windows Server 2003. The program displays a system tray icon
that seems to work fine when viewed from the PC's monitor. However, if I access the PC remotely
using Remote Desktop the icon does not appear. Many other icons appear, but not mine.
Using task manager, my program is running "SYSTEM".
NOTE: My program already handles TaskbarCreated for the case where explorer crashes.
Any ideas?
- 5
- Mcse >> Design ExamsI have one more exam to complete before im MCSE W2K... and
its one of the design exams. I've heard the 220 exam is
four hours long... which seems a little daunting! I asked
at my local test centre and they suggested 70-219. I dont
seem to hear much about 70-221... is that because everyone
has been put off by 70-216? Anyone out there got any
advice on the design exams for me (and any books you can
suggest would be helpfull)
Cheers,
Ant
- 6
- MFC >> Write Text on an imageHi
i've made an application that writes some text on an image..so far i've only
been able to write in english..does anyone know if TextOut() method of CDC
support text in languages other than english..
Regards
Usman Jamil
- 7
- MFC >> Max Text for CEdit ?Hi guys,
I tried pasting a lot of characters into a CEdit but it got truncated and I
couldn't type anything else in. It wasn't a huge amount of characters, just
source from a web page that can easily be viewed in Notepad.
What's going on ? Can I fix it ?
Thanks,
Robert
- 8
- 9
- Visual Basic >> Controlling ProductVersionHello - In VB.NET, how do I control product version, and access it for
reporting on my splash form? This is a simple .exe solution with a project
built out of a few forms and modules, and contains a setup project.
My vbproj file contains ProductVersion = "7.10.3077" . When I report
Application.ProductVersion, its value is 1.0.1723.16260 so clearly that
comes from somewhere else. Anyway, I don't want either of these values.
I would like to set the product version to 1.1.0, and report 1.1.0.build# .
So I'm looking for advice on how to set the value, and how to access it at
runtime.
Thanks in advance -- Dick Bixler
- 10
- Visual Basic >> re: printing certain pagesHi
I am trying to print certain pages from a textbox.I can all print pages but
i need to know how to print any page or pages i want to.
Does anyone know where i can start or have a sample of code.
Many thanks
Garry
- 11
- Visual Basic [VB] >> mysql date formathi, anyone know how to retrieve date from mysql database? i am using odbc
connection. which reader.getXXX shall I use? for example, my date in mysql is
2005-04-01. i have tried using reader.getstring, reader.getdate but all still
fail. If I use a getstring, it return "dd". (funny). using getdate returns
runtime error.
thanks in advance.
- 12
- 13
- VB Scripts >> Filename with date modified appended to filenameneed to find a way to change filenames that relect the filename and
the date modified. I have found numerous ways to get the current date
and time appended to the filename but nothing with date modified. I
have users that need to have this in the filename and I am in search of
some help in this matter. Example is a file named test.txt with a date
modified 1/31/2005. I would like the filename to be test
(1/31/2005).txt. Thanks in advance ...
- 14
- Visual Basic [VB] >> Business Layer and Data Layer application blocksHi,
A doc about a set of components I named as "Business Layer and Data Layer
application blocks" is available at
http://www.sabbasoft.com/myBlog/PermaLink.aspx?guid=070a8c55-b885-4b89-8f3a-a23801fb732e
You might be interested in reading it to get new ideas for your development
process.
As return I'll appreciate if you post me back any comment you might have
regarding this doc.
Best Regards
--
Enrico Sabbadin
Mail: sabbadin@sabbasoft.com
Website: http://www.sabbasoft.com
********
MTS - COM+ - VBCOM - Enterprise Services - Security FAQ
.NET & COM+ books selected list
********
Blog: http://www.sabbasoft.com/myblog
Affiliated Sites
http://www.vb2themax.com
http://www.codearchitects.com
- 15
- VB Scripts >> Determine if a file is openUsing Office 2003 and Windows XP;
Is there a way using a script (in a VBS script file) to determine if a file
is open?
If so, could someone please post example code?
Thanks much in advance.
|
| Author |
Message |
Cecelia

|
Posted: Thu Aug 28 16:00:58 CDT 2003 |
Top |
Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding
The reason I want to do so, is that I am sending to DOS and I am pretty
certain that it will not work.
Everything I've tried so far hasnt.
In my test environment (Windows to Windows) this works perfectly, but not
when sending to DOS:
Private Function bytearray2string(ByVal input As Byte()) As String
Dim output As String
output = System.Text.Encoding.Default.GetString(input)
Return output
End Function
Private Function string2bytearray(ByVal input As String) As Byte()
Dim output() As Byte
output = System.Text.Encoding.Default.GetBytes(input)
Return output
End Function
I have also tried this, to no avail in Windows:
Private Function bytearray2string2(ByVal input As Byte()) As String
Dim output As String = ""
Dim i As Integer = 0
'Dim vchar As Char
While i < input.Length
output = output & CChar(Chr(input.GetValue(i)))
i = i + 1
End While
Return (output)
End Function
Private Function string2bytearray2(ByVal input As String) As Byte()
Dim output(input.Length - 1) As Byte
Dim i As Integer = 0
For i = 0 To UBound(output)
output(i) = CByte(Asc(input.Chars(i)))
Next
Return (output)
End Function
The desired functions need to use no encoding and be able to work with
simple bytes. The values I'll be receiving wont be higher anyway.
I'd appreciate any feedback whatsoever.
regards,
J
Visual Studio20
|
| |
|
| |
 |
Tom

|
Posted: Thu Aug 28 16:00:58 CDT 2003 |
Top |
Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding
Why not use ASCII encoding, instead of 'Default'
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"I.Charitopoulos" <EMail@HideDomain.com> wrote in message
news:#EMail@HideDomain.com...
> The reason I want to do so, is that I am sending to DOS and I am pretty
> certain that it will not work.
> Everything I've tried so far hasnt.
>
> In my test environment (Windows to Windows) this works perfectly, but not
> when sending to DOS:
>
> Private Function bytearray2string(ByVal input As Byte()) As String
>
> Dim output As String
>
> output = System.Text.Encoding.Default.GetString(input)
>
> Return output
>
> End Function
>
>
>
> Private Function string2bytearray(ByVal input As String) As Byte()
>
> Dim output() As Byte
>
> output = System.Text.Encoding.Default.GetBytes(input)
>
> Return output
>
> End Function
>
>
>
> I have also tried this, to no avail in Windows:
>
> Private Function bytearray2string2(ByVal input As Byte()) As String
>
> Dim output As String = ""
>
> Dim i As Integer = 0
>
> 'Dim vchar As Char
>
> While i < input.Length
>
> output = output & CChar(Chr(input.GetValue(i)))
>
> i = i + 1
>
> End While
>
> Return (output)
>
> End Function
>
>
>
> Private Function string2bytearray2(ByVal input As String) As Byte()
>
> Dim output(input.Length - 1) As Byte
>
> Dim i As Integer = 0
>
> For i = 0 To UBound(output)
>
> output(i) = CByte(Asc(input.Chars(i)))
>
> Next
>
> Return (output)
>
> End Function
>
> The desired functions need to use no encoding and be able to work with
> simple bytes. The values I'll be receiving wont be higher anyway.
>
> I'd appreciate any feedback whatsoever.
>
> regards,
> J
>
>
>
>
>
|
| |
|
| |
 |
I

|
Posted: Fri Aug 29 01:37:49 CDT 2003 |
Top |
Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding
ASCII Encoding uses 7 bits out of the byte, so I'd be losing 1 bit out of
every byte of data that comes in.
I want to use the extended ASCII that uses all 8 bits, for values of 0 to
255.
"Tom Spink" <EMail@HideDomain.com> wrote in message
news:#EMail@HideDomain.com...
> Why not use ASCII encoding, instead of 'Default'
>
> --
> HTH,
> -- Tom Spink, Über Geek
>
> Please respond to the newsgroup,
> so all can benefit
>
|
| |
|
| |
 |
Armin

|
Posted: Fri Aug 29 04:12:11 CDT 2003 |
Top |
Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding
"I.Charitopoulos" <EMail@HideDomain.com> schrieb
> The reason I want to do so, is that I am sending to DOS and I am
> pretty certain that it will not work.
> Everything I've tried so far hasnt.
>
> In my test environment (Windows to Windows) this works perfectly, but
> not when sending to DOS:
> [...]
Maybe codepage 850 is what you're looking for.
System.Text.Encoding.GetEncoding(850)
Use it to convert from/to byte arrays. There are other codepages
See also:
http://www.microsoft.com/globaldev/reference/cphome.mspx
To find the right encoding, open a DOS window and enter
mode con cp<enter>
Should return the encoding you need (but I'm not sure)
--
Armin
|
| |
|
| |
 |
I

|
Posted: Fri Aug 29 09:55:11 CDT 2003 |
Top |
Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding
Thanx a lot for the tip. Will try that.
Seems like a reliable way of getting the encoding.
> Maybe codepage 850 is what you're looking for.
>
> System.Text.Encoding.GetEncoding(850)
>
> Use it to convert from/to byte arrays. There are other codepages
>
> See also:
> http://www.microsoft.com/globaldev/reference/cphome.mspx
>
> To find the right encoding, open a DOS window and enter
> mode con cp<enter>
>
> Should return the encoding you need (but I'm not sure)
>
> --
> Armin
>
|
| |
|
| |
 |
| |
 |
Index ‹ Visual Studio ‹ Visual Basic [VB] |
- Next
- 1
- Visual Basic [VB] >> excell in the process windowhi i have a windows service that uses an excell workbook
when i create the excell app
i cant distroy it after i am finished i am using this code
whats wrong?
thanks
Dim processes1(), p1 As Process
Try
processes1 = Process.GetProcesses()
For Each p1 In processes1
If Not (p1.MainModule Is Nothing) Then
If
System.IO.Path.GetFileName(p1.MainModule.FileName).ToLower() = "excel.exe"
Then
Try
p1.Close()
'p1.CloseMainWindow()
Catch er1 As Exception
MsgBox(er1)
End Try
'Exit For
End If
End If
Next
Catch ex As SystemException
MsgBox(ex.message)
End Try
- 2
- Visual Basic >> Integration with Word, can this be done?Here is what I have to accomplish, and I want to know if this can be done,
and pointers on how can this be done.
1) I need to start a new Word document using a template provided by the
customer. The customer will provide different templates, and my code would
know wish template to invoke. The question is what methodology do I use to
start the new Word doc?
2) At the end when the user saves the document, I need to send a copy of
this new created document by email to a destination. The destination may
change, and the settings could be saved in a INI file (TBD). My question is
can I override the SAVE button in Word, or provide a special button on the
toolbar to be pressed when done. Don't know what to do ????
Any tips/pointers would be appreciated. Thanks in advance for your reply.
Helene (Challenge by this task. Does not know where to start?)
- 3
- MFC >> 2 "type" problems...Hi,
(Follow up to microsoft.publicisa.sdk-dev)
I'm under VC++ 5.0 and try to use functions from ISA SDK.
1)I wonder how could I fill the WCHAR psz[100] with a CString content ?
Here is the code:
--------------------
WCHAR psz[100];
wcscpy(psz,L"MyString"); //this works
---------------------
But, I need to have MyString come from a CString
2)This code always return values <=255.
long l = fpcDestinationSet->Count;
ie: If I have 350 elements, the long l is : 94 (350%256)
even if I try the C++ way :
long count;
fpcDestinationSet->get_Count(&count);
printf("Destination Set : %s count : %ld\n", (char*)
fpcDestinationSet->Name,count);
the "Count" (get_Count() method for DestinationSet is here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/isa/isaobj2_9o6c.asp
- 4
- Visual Basic >> Using timersHello,
1.
Is there any 'optimal' number of timers can be used on one form?
2.
Which design will be more efficient:
A. using one timer and combine different events using If... Then
statements.
Because each event requires different time interval change timer
intervals for each event will be included in the code
or
B.
For each event use different timer with preset time interval
Your thoughts please,
Jack
- 5
- Visual Basic >> collection clone?is there an optimal way to clone a collection? i was going to do something
like:
...
Private m_Collection As Collection
...
Public Function Clone() As Collection
Set Clone = New Collection
Dim Item As Variant
For Each Item In m_Collection
Clone.Add Item
Next
End Sub
Problem is that I loose my Index. Is there a better way?
Thanks,
Craig Buchanan
- 6
- 7
- Visual Basic >> restricting the height of a formon a form i have a label control
in the forms Resize event i have the following code:
--------------------------------------------------
Label1.Height=Me.ScaleHeight * .5
--------------------------------------------------
i want it for the user to be impossible to make the form's height any
smaller when the labels height is smaller then say 2000 twips
any suggestions ?
tia
pc
- 8
- Visual Basic >> Dr Watson errorI have a VB6 program that receives data using socket and save the data to a
SQL Server 2000 database.
It has Windows 2000 SP4 with all hot patches in it. It has 2 gig of RAM.
The program had been running for years with no problem, but for the last 3
days it had died exactly at 3 AM. No error on the screen, but there is Dr.
Watson error (it is in drwtsn32.log).
The error in drwtsn32.log is:
Exception number: c0000005 (access violation) --> this is on this VB
program.
I do not know how to read Dr Watson log, but the "Raw Stack Dump" contains
c:\winnt\system32\comsvcs.dll.
I searched on the internet and found that there was an Access Violation
error with comsvcs.dll, and the fix is to install the latest Windows
patches, which we already did. We also increased the memory from 1 gig RAM
to 2 gig. The program still happens.
There is no scheduled task running at 3 AM.
Does anybody know how to read Dr Watson log ?
How can I fix this problem ?
Thank you very much.
- 9
- Visual Basic [VB] >> Flexibility vs ReliabilityMy co-worker and I are debating Flexibility vs. Reliability.
For example this method is highly flexible:
Public Shared Function GetList(ByVal whereClause As String) As String
strSQL = "SELECT field1,field2,field3,field4,field5 FROM table1 "
If whereClause <> String.Empty Then
strSQL &= "WHERE " & whereClause
End If
Return strSQL
End Function
My co-worker agress that it is flexible but would prefer to use more
reliable techniques like Overloading and Strong Typing of parameters.
Public Shared Function GetList(ByVal field1Value As String, ByVal
field2Value As Integer) As String
strSQL = "SELECT field1,field2,field3,field4,field5 FROM table1 "
strSQL &= "WHERE field1='" & field1Value & "' AND field2=" &
field2Value
Return strSQL
End Function
My argument is that you can't predict every possible combination of field
values and arguments so the number of where clauses and overloaded methods
would grow to ridiculous proportions.
Have other people faced this issue? If so what did you think about it?
Appreciate any insights and experiences.
Thanks!
--
Joe Fallon
- 10
- Visual Basic >> changeHello, I want to let the commandbutton1 to change for example the
letter "a" into letter "z" and letter "b" into "y" and so on from the
textbox1 to textbox1 again... how can this be done??
Thanks in advance...
- 11
- MFC >> mimic cin abilityI am connecting with a hardware device that sends data
via keyboard emulation. That is it sends the data as if
it were typed on the keyboard. So I wrote a shell that
used cin to get those input values. Now I am trying to
port my text based system to a dialog so it can be user
friendly.
So I want to have an edit box that has the cursor put
there. I know you can use GetDlgItemText to get text
from an edit box, but I don't know of anyway to make the
GetDlgItemText wait until a new line character like cin
does? I have also tried
CWnd* pntr=GetDlgItem(id); to see if there are any
particular methods available to you that way that would
help but I couldn't figure it out. Anybody know how to
do this one?
I also have not been able to find a method to allow me to
make the edit box the focus. the SetFocus returns a
pointer but doesn't take an id to say what is being
focused.
Thanks in advance for answering the newbie's questions.
Danny
- 12
- Visual Basic [VB] >> LoopI need to loop through a index change event, however whenever i loop
through the first combo box always report back correctly its when i
move to the next combobox, that instead of changing the second combo
box it will change the background of the first combo box.
What im i doing wrong?
For intloop = 0 To cboArraylist.Count - 1
If (CType(cboArraylist(intloop), ComboBox).Text) = "Go"
Then
CType(cboArraylist(intloop), Object).BackColor =
Color.LawnGreen
ElseIf (CType(cboArraylist(intloop), ComboBox).Text) = "No
Go" Then
CType(cboArraylist(intloop), Object).BackColor =
Color.Tomato
End If
Next
- 13
- Visual Studio C++ >> nmake and extra include pathHi
I run nmake from visual studio (.NET 2003) command prompt.
This means that the enviroment is correct.
My question is: How do I add additional include and library paths to
the enviroment??
Peter
- 14
- Visual Basic [VB] >> After days and hours, could not achieve to do this ...Hello MVPs and other Gurus,
I (urgently) need to fill a TreeView in a Windows form with the
data of a text file structured as under :
- begin
Root\
Root\Node1\
Root\Node1\SubNode11\
Root\Node1\SubNode11\SubNode111\
Root\Node1\SubNode11\SubNode112\
Root\Node1\SubNode12\
Root\Node1\SubNode12\SubNode121\
Root\Node1\SubNode12\SubNode122\
Root\Node1\SubNode12\SubNode123\
Root\Node1\SubNode13\
Root\Node1\SubNode14\
Root\Node2\
Root\Node2\SubNode21\
Root\Node2\SubNode21\SubNode211\
Root\Node2\SubNode21\SubNode211\SubNode2111\
Root\Node2\SubNode21\SubNode211\SubNode2111\SubNode2112\
Root\Node2\SubNode21\SubNode211\SubNode2111\SubNode2112\SubNode21121
Root\Node2\SubNode21\SubNode212\
Root\Node2\SubNode21\SubNode213\
Root\Node3\
- end
Any name in this example is fake and can be replaced
with a whatever string matching the structure.
I easily extracted each Node.Text from the file, but after days
and hours roaming around the availabilities of VB.Net (Visual Studio 2003)
and various Internet Sites, I could not achieve to fill the TreeView properly.
;-(
Any tip, link, code, advice, and support will be highly appreciated.
TIA to all.
Patrick Penet
:-)
PS: sorry for crossposting in the VB.Net and Visual Studio related NGs
but it's a matter of time now.
--
Remove the dot to answer in my box
phpe.net@club-internet.fr
====================
- 15
- VB Scripts >> Regular Expression Replace : $1 shows up as literal.Hi There.
I have searched the news groups and cannot seem to find an answer to my
situation. Basically, I have the following function (that appears
standard across all posts):
Public Function Highlight(p_sFind, p_sSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern=p_sFind
RegEx.IgnoreCase=True
RegEx.Global=True
Highlight = RegEx.Replace(p_sSearch,"<b>$1</b>")
End Function
However, wheneven I execute it on some code, I get a literal "$1"
rather then the string I searched for.
For example, Highlight ("Harv", "Harvard Medical School") returns:
"<b>$1</b>ard Medical School" rather than "<b>Harv</b>ard Medical
School".
Does anyone have any idea what I am doing wrong. Is any server
requirements in using this tool?
Thanks
Jason
|
|
|