|
how to convert ascii to hexa using vb?
for example...hexa 13 = ascii 31(1) 33(3)
now i have it in ascii but i need to combine and convert this into 13 instead of 31 33...
i need to create a function to do this in a class library den after dat call it from the app source code
help please!!
thanks alot!!
|
|
|
|
|
so what you need is a function that:
- consumes two characters
- checks they represent one hex digit (30...39,41...46,61...66)
- remember the value, lets call it HI
- consumes two characters
- checks they represent one hex digit (30...39,41...46,61...66)
- remember the value, lets call it LO
- return 16*HI + LO
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Not really sure exactly what you have and what you need, so here's a couple options:
If you have an byte/integer variable and you what the hex string, you need x.ToString("X2")
If you have the two characters '1' and '3' in a string, you need Integer.Parse('13', Globalization.NumberStyles.AllowHexSpecifier)
|
|
|
|
|
I’ve converted code for text justification from C# to VB Express 2005
C# version:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class AdvRichTextBox : RichTextBox
{ public new TextAlign SelectionAlignment
{
get
{
PARAFORMAT fmt = new PARAFORMAT();
fmt.cbSize = Marshal.SizeOf( fmt );
SendMessage( new HandleRef( this, Handle ),
EM_GETPARAFORMAT,
SCF_SELECTION, ref fmt );
if ( ( fmt.dwMask & PFM_ALIGNMENT ) == 0 )
return TextAlign.Left;
return ( TextAlign )fmt.wAlignment;
}
set
{
PARAFORMAT fmt = new PARAFORMAT();
fmt.cbSize = Marshal.SizeOf( fmt );
fmt.dwMask = PFM_ALIGNMENT;
fmt.wAlignment = ( short )value;
SendMessage( new HandleRef( this, Handle ),
EM_SETPARAFORMAT,
SCF_SELECTION, ref fmt );
}
}
protected override void OnHandleCreated( EventArgs e )
{
base.OnHandleCreated( e );
SendMessage( new HandleRef( this, Handle ),
EM_SETTYPOGRAPHYOPTIONS,
TO_ADVANCEDTYPOGRAPHY,
TO_ADVANCEDTYPOGRAPHY );
}
private int updating = 0;
private int oldEventMask = 0;
private const int EM_SETEVENTMASK = 1073;
private const int EM_GETPARAFORMAT = 1085;
private const int EM_SETPARAFORMAT = 1095;
private const int EM_SETTYPOGRAPHYOPTIONS = 1226;
private const int WM_SETREDRAW = 11;
private const int TO_ADVANCEDTYPOGRAPHY = 1;
private const int PFM_ALIGNMENT = 8;
private const int SCF_SELECTION = 1;
[StructLayout( LayoutKind.Sequential )]
private struct PARAFORMAT
{
public int cbSize;
public uint dwMask;
public short wNumbering;
public short wReserved;
public int dxStartIndent;
public int dxRightIndent;
public int dxOffset;
public short wAlignment;
public short cTabCount;
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 32 )]
public int[] rgxTabs;
public int dySpaceBefore;
public int dySpaceAfter;
public int dyLineSpacing;
public short sStyle;
public byte bLineSpacingRule;
public byte bOutlineLevel;
public short wShadingWeight;
public short wShadingStyle;
public short wNumberingStart;
public short wNumberingStyle;
public short wNumberingTab;
public short wBorderSpace;
public short wBorderWidth;
public short wBorders;
}
[DllImport( "user32", CharSet = CharSet.Auto )]
private static extern int SendMessage( HandleRef hWnd,
int msg,
int wParam,
int lParam );
[DllImport( "user32", CharSet = CharSet.Auto )]
private static extern int SendMessage( HandleRef hWnd,
int msg,
int wParam,
ref PARAFORMAT lp );
}
public enum TextAlign
{
Left = 1,
Right = 2,
Center = 3,
Justify = 4
}
}
VB Version
Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
'<Designer("System.Windows.Forms.Design.ParentControlDesigner, SystemDesign", GetType(IDesigner))> _
<Serializable()> _
Public Class RichTextBoxEx
Inherits RichTextBox
Enum TextAlign
Left = 1
Right = 2
Center = 3
Justify = 4
End Enum
<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByVal lp As PARAFORMAT) As Integer
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure PARAFORMAT
Public cbSize As Integer
Public dwMask As UInteger
Public wNumbering As Short
Public wReserved As Short
Public dxStartIndent As Integer
Public dxRightIndent As Integer
Public dxOffset As Integer
Public wAlignment As Short
Public cTabCount As Short
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
Public rgxTabs() As Integer
' PARAFORMAT2 from here onwards.
Public dySpaceBefore As Int32
Public dySpaceAfter As Int32
Public dyLineSpacing As Int32
Public sStyle As Short
Public bLineSpacingRule As Byte
Public bOutlineLevel As Byte
Public wShadingWeight As Short
Public wShadingStyle As Short
Public wNumberingStart As Short
Public wNumberingStyle As Short
Public wNumberingTab As Short
Public wBorderSpace As Short
Public wBorderWidth As Short
Public wBorders As Short
End Structure
Private updating As Int32 = 0
Private oldEventMask As Int32 = 0
'Constants from the Platform SDK.
Private Const EM_SETEVENTMASK As Integer = 1073
Private Const EM_GETPARAFORMAT As Integer = 1085
Private Const EM_SETPARAFORMAT As Integer = 1095
Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
Private Const WM_SETREDRAW As Integer = 11
Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
Private Const PFM_ALIGNMENT As Integer = 8
Private Const SCF_SELECTION As Integer = 1
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
MyBase.OnHandleCreated(e)
'Enable support for justification.
SendMessage(New HandleRef(Me, Handle), _
EM_SETTYPOGRAPHYOPTIONS, _
TO_ADVANCEDTYPOGRAPHY, _
TO_ADVANCEDTYPOGRAPHY)
End Sub
Public Overloads Property SelectionAlignment() As TextAlign
Get
Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)
' Get the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_GETPARAFORMAT, _
SCF_SELECTION, fmt)
' Default to Left align.
If ((fmt.dwMask & PFM_ALIGNMENT) = 0) Then
Return TextAlign.Left
End If
If fmt.wAlignment = 1 Then
Return TextAlign.Left
ElseIf fmt.wAlignment = 2 Then
Return TextAlign.Right
ElseIf fmt.wAlignment = 3 Then
Return TextAlign.Center
ElseIf fmt.wAlignment Then
Return TextAlign.Justify
End If
End Get
Set(ByVal value As TextAlign)
Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)
fmt.dwMask = PFM_ALIGNMENT
fmt.wAlignment = CShort(value)
' Set the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_SETPARAFORMAT, _
SCF_SELECTION, fmt)
End Set
End Property
End Class
It was working in C# but in vb it gives error that “AccessViolationException was unhandled” at the following line
SendMessage(New HandleRef(Me, Handle), _
EM_SETPARAFORMAT, _
SCF_SELECTION, fmt)
Plz can anyone tell me what's the problem
|
|
|
|
|
In your C# code you pass fmt by reference. This allows the OS to alter it. In VB.Net, you pass it by value; this doesn't. The OS will probably try to alter it, then when it finds it can't, will throw an AccessViolationException. To fix it, pass the fmt variable by reference, using ByRef
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Computafreak wrote: The OS will probably try to alter it, then when it finds it can't, will throw an AccessViolationException.
More importantly, the size will be all wrong because the structure is much larger than a reference.
|
|
|
|
|
I tried using "ByRef fmt" but it gives error saying "Expression required". Am i missing smthg?
P.S: Sorry i hav never b4 worked with "SendMessages"
|
|
|
|
|
I hav done it. thnx to u all.
|
|
|
|
|
hi,
i have to insert string like HELLO's
but this string shoes some error.
i want to insert single quote in ms access DB.
NOTE : i have to insert dynamic string through textbox
thanks in advance
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
you can use '' to do a quote. Of course, you'd do better to use parameterised querys, and not leave yourself open to SQL injection
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi All,
Regarding SMS, through VB6 application, how can we send the SMS where a SMS device is Connected to USB Port. Anybody having the information please let me know.
Regards,
Jay.
|
|
|
|
|
you will almost certainly need a third party library. I doubt anyone still writes or supports those for VB6 tho, given how out of date and obsolete it is
If VB6 can talk to a webservice, you may find a webservice you can use. I doubt it would be free.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi Experts,
After my validation my control goes to the next cell..I have written the code to focus the current cell.But could not get the same....
code is --->
Private Sub dgvstock_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvstock.CellValidating
Dim cell As DataGridViewCell = dgvstock.Item(e.ColumnIndex, e.RowIndex)
Dim ret As Integer
If cell.IsInEditMode Then
Dim c As Control = dgvstock.EditingControl
Select Case dgvstock.Columns(e.ColumnIndex).Name
Case "Sr No.", "Amount"
c.Text = CleanInputNumber(c.Text)
If c.Text = "" Then
ret = MessageBox.Show("Enter Only Numbers", "Invalid Input")
If ret = 1 Then
dgvstock.CurrentCell = dgvstock(e.ColumnIndex, e.RowIndex)
//Here i want the focus on current cell
End If
End If
End Select
End If
End Sub
Private Function CleanInputAlphabet(ByVal str As String) As String
Return System.Text.RegularExpressions.Regex.Replace(str, "[0-9\b\s-]", "")
End Function
|
|
|
|
|
//This will written in the EditingControlShowing event of datagridview
If TypeOf e.Control Is TextBox Then
DirectCast(e.Control, TextBox).CharacterCasing = CharacterCasing.Upper
End If
|
|
|
|
|
Datagridview1.CurrentCell = Datagridview1('Your column index', Datagridview1.NewRowIndex)
Datagridview1.BeginEdit(True)
|
|
|
|
|
Dim cn As New OleDbConnection
Dim adapter As New OleDbDataAdapter
Dim dtset As New DataSet
Dim dt As New DataTable
Dim cmd As New OleDbCommand
Dim sqlconnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sourceDirectory & ";" & _
"Extended Properties=""Text;HDR=No;"""
cn.ConnectionString = sqlconnectionString
'Open the Jet connection to read the CSV file
Try
cn.Open()
Catch e As Exception
End Try
Try
'Connection to the csv file and dump the data into a dataset
cmd.Connection = cn
cmd.CommandText = "Select * from " & sourceFile
'Attempt to fill a Datatable with the data from the CSV
adapter.SelectCommand = cmd
adapter.Fill(dtset, "CSVdata")
dt = dtset.Tables("CSVdata")
cn.Close
I am trying to read a csv file without any headers but I am getting one record short of actual no of rows. Is there something I am missing. The HDR option isn't really helpful.
Thanks in advance
|
|
|
|
|
I want to be able to determine the drive letter of an external USB device. If I use DriveInfo, the device is rarely, if ever, detected. If I use Scripting.Drive it sees the external device each time. Why is this?
Code that does NOT work:
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim uutDrive As String
Dim drive As DriveInfo
For Each drive In allDrives
If drive.IsReady = True Then
If drive.VolumeLabel = WaffleVolumeLabel Then
uutDrive = drive.Name
Exit For
End If
End If
Next
Code that WORKS:
Dim fso As New Scripting.FileSystemObject
Dim drv As Scripting.Drive
Dim string_builder As New System.Text.StringBuilder
For Each drv In fso.Drives
If drv.IsReady Then
If drv.VolumeName = WaffleVolumeLabel Then
uutDrive = drv.DriveLetter & ":\"
End If
End If
Next
|
|
|
|
|
Hi,
There is quite a difference between "rarely" and "if ever" and without a crystal ball I'm not sure what "does not work" actually means.
It would be helpful to step through your code with the debugger to locate the point of failure.
I would initally find out if :
1) The code is being called at all
2) The allDrives array contain an entry for the USB drive
If allDrives is OK then step forward into the loop and figure out why your volume label is not being detected.
Is string comparison in VB.Net via the = operator case sensitive?
Alan.
|
|
|
|
|
Thanks for the response Alan!
What I mean by rarely is the any information on the attached external usb device is detected about 5% of the time that I run the code with the allDrives whereas as with the scripting.drives, the external usb device is detected each time. I am able to see all of other drives on my machine except the external USB device when stepping through the code. If I open file explorer, the external USB device is also shown. When I step through the code, most of the time no information on this device is seen (I've tried reading the drive name, the drive Format as well as the volume) and since none of this information is detected, I have concluded that for some reason, the allDrives isn't able to detect the device on a consistent basis.
So
(1) The code is being called as I can see other device
(2) The allDrives array does not contain entry for the desired device, but it does for another USB device (so an indication that the code can detect USB devices).
I do think the string comparison is case sensitive, but I have determined that this is not the problem as the block of code that works is able to make the match (and I also copied the volume name from file explorer to make sure the case would match).
|
|
|
|
|
Hi
I searched google for encryption algorithms to use
in vb 2008 and got one listed in CodeProject listed at
Making TripleDES Simple in Visual Basic .NET[^]
It encrypts the string fine but is not able to decrypt it
and shows the following message.
Length of the data to decrypt is invalid.
I searched google for the solution but not got any satisfying one.
what to do now?
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Prankur Rusia wrote: what to do now?
fix the bug in your code. Make sure what the encryption generated is entered into the decryptor without any change. without any details, noone can help you.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi Luc,
Can you please tell me what details you want?
My code is exactly as listed in the article shown above.
The string to encrypt is: encryptitman
The key I use is: 123456789012345678901234
The iv I use is : 12345678
The encryption goes on fine but the code is not able to decrypt the encrypted string.
I supply the encrypted string exactly to the decrypt function.
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
The article is followed by some discussions, where one of the participants is having the problems you're having, and he came up with a solution for it.
If it still would not work, you'd better post there.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
have created function in class file.
Public Shared Function dsCntrctET() As DataSet
Dim sqlCntrct As String = "Select * from CNTRCT_ET where CNTRCT_ID=" & CISCNO
Dim cmdCISContract As New OracleCommand
Dim daCISCntrct As New OracleDataAdapter
Dim dsCISCntrct As New DataSet
Dim cmdCISBuilder As New OracleCommandBuilder
Try
With cmdCISContract
.Transaction = myTransCIS
.CommandText = sqlCntrct
.Connection = cnCIS
End With
daCISCntrct = New OracleDataAdapter(cmdCISContract)
daCISCntrct.FillSchema(dsCISCntrct, SchemaType.Source)
cmdCISBuilder = New OracleCommandBuilder(daCISCntrct)
With daCISCntrct
.TableMappings.Add("Table", "CNTRCT_ET")
.Fill(dsCISCntrct)
.SelectCommand = cmdCISContract
.InsertCommand = cmdCISBuilder.GetInsertCommand
.UpdateCommand = cmdCISBuilder.GetUpdateCommand
.DeleteCommand = cmdCISBuilder.GetDeleteCommand
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return (dsCISCntrct)
End Function
it returns dataset that i can use for getting value from table.
but while saving data, i have to use dataadapter for da.update(ds,"table") and ds.acceptchanges.
this i have to use in multiple forms as this data comes from 3rd party so i dont want to write this in every form . so i thought how to return data adapter and dataset from the same function. as i wanted to use daCISCntrct and dsCISCntrct.
|
|
|
|
|
Pass any other objects you want to return in as an out parameter.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|