|
You can't. Those are the only two options you have.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OK, thank you for saving my time.
chatura
|
|
|
|
|
Hello!
I got an answer from Dave but whatever I tried didn't wotk out to solve PInvokeStackImbalance problem. I am using VS 2005. Eventough I changed the Integers in the GetshortPath declaration below I still got the same problem.
I have included the code below. If you can see the problem, please let me know.
Thanks!
<dllimport("kernel32.dll", setlasterror:="True," charset:="CharSet.Auto)"> _
Public Shared Function GetShortPathName(ByVal longPath As String, <marshalas(unmanagedtype.lptstr)> ByVal ShortPath As StringBuilder, <marshalas(unmanagedtype.u4)> ByVal bufferSize As Integer) As Integer
End Function
Private Function GetDosPath(ByVal LongPath As String) As String
Dim sb As New StringBuilder(1024)
On Error Resume Next '++
Dim retVal As Integer = Interop.GetShortPathName(longPath, sb, 1024) '<-- error occurs at that line
If retVal <> 0 Then
Dim sTemp As String = sb.ToString()
GetDosPath = sTemp
Else
Console.WriteLine("Error occured. GetLastError returns {0}.", Marshal.GetLastWin32Error())
End If
End Function
|
|
|
|
|
You've supplied everything except the one piece we need - the original C function header!
Is this the GetShortPathName in the WIn32 Api??? If so, then the Declare should look like this (from PInvoke.net):
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function GetShortPathName(ByVal longPath As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal ShortPath As StringBuilder, _
<MarshalAs(UnmanagedType.U4)> ByVal bufferSize As Integer) As Integer
End Function
Private Sub TestShortPath()
Dim sb As New StringBuilder(1024)
Dim longPath As String
Dim sFileName As String
longPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
Dim retVal As Integer = Interop.GetShortPathName(longPath, sb, 1024)
If retVal <> 0 Then
Dim sTemp As String = sb.ToString()
MessageBox.Show(sTemp)
Else
Console.WriteLine("Error occured. GetLastError returns {0}.", Marshal.GetLastWin32Error())
End If
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 13:31 Sunday 5th February, 2006
|
|
|
|
|
Sorry Dave! Here is the class header.. Whatever I tried I got the same problem...
Public Class Interop
<dllimport("kernel32.dll", setlasterror:="True," charset:="CharSet.Auto)"> _
Public Shared Function GetShortPathName(ByVal longPath As String, <marshalas(unmanagedtype.lptstr)> ByVal ShortPath As StringBuilder, <marshalas(unmanagedtype.u4)> ByVal bufferSize As Integer) As Integer
End Function
End Class
|
|
|
|
|
No, no, no, ... The original C function header that you're trying to call, not what you think the VB declaration should be.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
GetShortPathName
The GetShortPathName function retrieves the short path form of the specified path.
DWORD GetShortPathName(
LPCTSTR lpszLongPath,
LPTSTR lpszShortPath,
DWORD cchBuffer
);
Parameters
lpszLongPath
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
Windows Me/98/95: This string must not exceed MAX_PATH characters.
lpszShortPath
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer
[in] Size of the buffer pointed to by lpszShortPath, in TCHARs.
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.
If the lpszShortPath buffer is too small to contain the path, the return value is the size of the buffer, in TCHARs, required to hold the path. Therefore, if the return value is greater than cchBuffer, call the function again with a buffer that is large enough to hold the path.
If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.
|
|
|
|
|
This looks like it came out of MSDN. In that case, I've already shown you what the VB.NET declaration should look like.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Please help me. How do i randomly select a value, any value. Is there a method for this?
rzvme
|
|
|
|
|
These will get a random value that is >=0 and <1. To get any more specific code you have to ask a more specific question.
VB:
Randomize<br />
x = Rnd()
VB.NET:
Dim r as New Random()<br />
x = r.NextDouble()
---
b { font-weight: normal; }
|
|
|
|
|
well i need an integer value from 1 to 101!
rzvme
|
|
|
|
|
Well, that is quite more specific.
VB:
Randomize<br />
x = Int(Rnd() * 101) + 1
VB.NET:
Dim r as New Random()<br />
x = r.Next(101) + 1
---
b { font-weight: normal; }
|
|
|
|
|
|
Dim r As New Random, x As Integer
x = 10 * (r.Next(10) + 1)
chatura
|
|
|
|
|
I have to import a image file(map of a particular area) and then work on it...so as find path for an particular area and route information to a place..so how to proceed with..please help me to get a start and assist me with some codes on this project...also shortest route calculation is embedded on my project using nodes and links...iam new to vb.net so please help me..
|
|
|
|
|
GIS systems tend to work on vector data where the information about the paths are loaded into the system as a series of links and nodes. This information is not present in an image file and would have to be added by the user as current technology is not sufficient for a PC to work this out on its own in a reasonable amount of time.
haripaddu wrote: shortest route calculation is embedded on my project using nodes and links
Search the internet for the "Travelling Salesman Algorithm".
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
This is one that seemed simple at first, but gives me a big headache:
How to get the start- and end-dates of the current week, or last week?
Math has never been my forte anyway. Is there a simple way to do this?
Thanks in advance!
Hiske
|
|
|
|
|
It's easy if you think about it and just look at the documentation for DateTime[^].
To get the date of the beginning of the week, all you need is the current date (Now), what the current day of the week is (Now.DayOfWeek), then just subtract the current day of the week from the current date (Now.AddDays(-Now.DayOfWeek)). To get the last date of the week, just add 6 days to the beginning of the week.
Dim currentDate As Date = Now()
Dim beginDate As Date = currentDate.AddDays(-currentDate.DayOfWeek)
Dim endDate As Date = beginDate.AddDays(6)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave!
Your code sure is al lot shorter than what I had.
This makes for a big improvement...
Hiske
|
|
|
|
|
I am new to programming and wanted to create a little project to learn from. How would I go about saving the source code of a basic HTML webpage to a text file? Any advise links or code would be helpful. I know I am a little over my head right now, but the best way to learn to swim is by jumping in. Thanks.
|
|
|
|
|
You'll have to exaplin this a bit more. Save the HTML from what? A page you're viewing or something you're editing in a TextBox or some other control?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well I just wanted to connect to a page with the program (not view) and then save the source code as a text file so that I can copy some parts of it to a new html file.
|
|
|
|
|
You can get the document text from the WebBrowser controls (I'm assuming your using this!) DocumentText property. All you have to do is open a file and write this string out to it.
Dim sw As New StreamWriter("filepath")
sw.Write(WebBrowser1.DocumentText)
sw.Close()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
A newbie here finally migrating from VB6 to VB 2005.
What is the best way to populate a dataset from a text file? The text file is comma-delimited and doesn't include first line header info.
In VB6, I read the file into a array type declaration (Structure) and then pushed into a db table. I had to take a combination of the fields in the array and combine into single column for the database.
In VB 2005, I would like to take this file and read into a dataset(datatable) and declare my columns plus push mutiple fields into those declared columns. Once in the poper format in a grid or list push to a SQL Server table.
Is this possible? Any help or leads is appreciated. I like what I see thus far in 2005 and excited about migrating.
I am assuming I can use streamreader or such and use a split?
Thanks,
RG
|
|
|
|
|
Hi
I'd first Instantiate a New Datatable, and then use the DataAdapter.FillSchema method. This will give your new table all the column names from the SQL table you are going to update, as well as any constraints like primary keys etc. This will help since you will get an exception if you try to add something to the datatable that is not suitable with your SQL database table.
<br />
Private Sub ImportTextFile()<br />
Dim dt as new DataTable<br />
GetTableSchema(dt, "SELECT * From MyTable")<br />
Dim TextFile() as String<br />
'<br />
'Populate your TextFile() array from the text file<br />
'<br />
<br />
Dim dr As DataRow<br />
For i As Integer = 0 To TextFile.GetUpperBound(0) - 1<br />
dr = dt.NewRow<br />
dr.Item(0) = TextFile(i)<br />
dt.Rows.Add(dr) 'Maybe Put This is a Try...Catch Block<br />
Next<br />
End Sub<br />
<br />
<br />
Public Function GetTableSchema(ByRef dt As DataTable, ByVal SelectString As String) As Boolean<br />
Dim path As String = Application.StartupPath<br />
Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _<br />
& " Data source= C:\MyDB.mdb"<br />
Dim strSelect As String = SelectString<br />
<br />
Dim cn As New OleDb.OleDbConnection(cnStr)<br />
Dim cmd As New OleDb.OleDbCommand(strSelect, cn)<br />
Dim da As New OleDb.OleDbDataAdapter(cmd)<br />
cmd.CommandTimeout = 5<br />
Try<br />
cn.Open()<br />
da.FillSchema(dt, SchemaType.Source)<br />
Return True<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message)<br />
Return False<br />
Finally<br />
cn.Close()<br />
End Try<br />
End Function
|
|
|
|