|
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
|
|
|
|
|
How to get the path for font folder ( without try catch statements)
Please help me.
chatura
|
|
|
|
|
My first question would be "Why would you want to?" I've never seen the question asked, ever..., so I'm just woundering what you want to do in that folder.
Imports System.Io
.
.
.
Dim sysFolder As String = Environment.GetFolderPath(SpecialFolder.System)
sysFolder = Path.Combine(sysFolder, "Fonts")
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you Dave
I wanted to copy a font file to that folder
But my fonts folder’s path is , <sysdirve>\WINDOWS\Fonts ,not <sysdirve>\WINDOWS\System32\Fonts, therefore, I modified it like this
Imports system.io
.
.
.
Dim sysFolder As String = Environment.GetFolderPath (Environment.SpecialFolder.System)
sysFolder = Path.Combine(Microsoft.VisualBasic.Left(sysFolder, 11), "Fonts")
Thank you very much again
chatura
-- modified at 2:19 Sunday 5th February, 2006
|
|
|
|
|
Whoops! My bad!
Hmmm...Does the font actually get installed properly if you copy it in like that? Make sure the font works when you're done!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes, that’s true. It didn’t work. To activate it, I had to go to the fonts folder and double click that font file.
Do you (anybody) have any suggestions?
chatura
|
|
|
|
|
You might want to try copying the file into the Fonts folder using the Shell function SHFileOperation . This will cause the SHell to copy the file and possibly install it correctly.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know Shell function, but what is SHFileOperation? How do I use it to copy my font file?
chatura
|
|
|
|
|
The Win32 API Shell functions...SHFileOperation tells the Windows Shell to do the file copy, just like if you were to drag and drop a file in Explorer.
SHFileOperation[^] on PInvoke.net
SHFileOperation[^] on MSDN
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have been searching the internet and reviewing books for a while now trying to determine how exactly to read/write directly to the disk in NTFS using Visual Basic. I have had little success and I am hoping that someone here can help me.
I believe that it comes down to API calls using readfile, etc. to get a handle to the drive and process the information, but I'm at a loss as to how to actually program this.
I've seen a good example in C++ here from T.YogaRamanan but I have not worked in that language for several years and can not break down the logic.
My goal is to write a program that will display the contents of a drive (including deleted files) based on the Master File Table.
Any help would be appreciated but what I am hoping for is someone to clearly identify the steps involved: Step one do this, Step two do that, etc.
Sample Code would be a definite bonus.
Thank You
|
|
|
|
|
Wow, haven't seen this one in a while...
The .NET BCL doesn't have anything that would help you do this. You'll have to P/Invoke all the Win32 API functions to do this. You need CreateFile[^] to open the disk and get a handle. The .NET BCL File functions won't work with disk/volume handles and won't open those either. Once you have the handle, you can only use the Win32 API file functions to read/write the disk.
There's no examples of doing this in VB.NET that I know of. Most of what you'll find is in C++.
The hard part of this is setting up all the calls to CreateFile, ReadFile, WriteFile, and CloseHandle. You'll also need to declare the structures and enums you'll need to call these functions. But, once that's done, it's a matter of calling CreateFile to open the drive, the using ReadFile and WriteFile, to read/write the disk sectors, then CloseHandle to release the disk.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for the reply.
Sorry for the confusion, when I referred to Visual Basic, I meant Visual Basic 6, not VB.NET. I never use .net for anything, not yet anyway.
I know it is possible as I've seen demos done in VB but have no accompanying source code.
I have the general idea of what steps are involved but I can not seem to get it working. MSDN only lists the api names but does not provide an example in how to actually use them to achieve anything (except for c++ or c# code).
If anyone has a code sample in Visual Basic 6 of setting up whatever structures, enums and calling the necessary functions, I would appreciate it.
Again, to be clear, I am using Visual Basic 6 on Windows XP with a NTFS formatted drive (obviously) and I am trying to generate a list of all files and folders on the drive (including deleted ones). My main objective here is to access the Master File Table and list all of it's records.
Thanks,
Dan
|
|
|
|
|
IH8Microsoft wrote: I know it is possible as I've seen demos done in VB but have no accompanying source code.
It is possible. I just have never seen any example code for it.
IH8Microsoft wrote: I am trying to generate a list of all files and folders on the drive (including deleted ones). My main objective here is to access the Master File Table and list all of it's records.
This is going to force you to do FAR more than just read disk sectors. Now you're getting into parsing the NTFS structures. You'll want to see if you can find the book "NT File System Internals" (which is out of print BTW). It's the best source of information ever written on NTFS.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'll keep my eyes open for that book, maybe it is still available somewhere.
I have some documentation that well describes the NTFS structure, the records, headers, attributes, etc. but once again, it is the technical syntax and logic in Visual Basic that I am having trouble with. I know that once I get the first few lines working, the rest will follow.
I guess I was just hoping that some had done something like this before and had the first few lines to get me started.
I any case, I'm going to keep working on it as it has now become a personal mission
Thank you for your time, I appreciate it.
|
|
|
|
|
Hello!
I have been trying to resize an image (which is loaded to Picturebox1). The actual image size is greater than the size of Picturebox1. The picturebox1 uses strechimage attribute. My aim is to adjust the loaded image size and write it as a watermark on to another image. It writes but it doesn't resize the image according to size of the picturebox1 Width & Height. It is using the original size of the image when it writes.
If you have an idea why that happens, please let me know!
Thanks!
CODE::
Private Function DrawImageCallback(ByVal callBackData As IntPtr) As Boolean
'Test for call that passes callBackData parameter.
If callBackData.Equals(IntPtr.Zero) Then
' If no callBackData passed, abort DrawImage method.
Return True
Else
' If callBackData passed, continue DrawImage method.
Return False
End If
End Function
' Copy the watermark image over the result image.
Private Sub DrawWatermark(ByVal watermark_bm As Bitmap, _
ByVal result_bm As Bitmap, ByVal x As Integer, ByVal y As Integer)
Dim imageCallback As New Graphics.DrawImageAbort(AddressOf DrawImageCallback)
Dim imageCallbackData As New IntPtr(1)
' Create rectangle for adjusted image.
Dim destRect2 As New Rectangle(PictureBox1.Location.X, PictureBox1.Location.Y, PictureBox1.Width, PictureBox1.Height)
Dim es As Graphics = Graphics.FromImage(result_bm)
es.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
' Create image attributes and set large gamma.
Dim imageAttr As New ImageAttributes()
'imageAttr.SetGamma(4.0F)
' Draw adjusted image to screen.
es.DrawImage(watermark_bm, destRect2, x, y, PictureBox1.Width, PictureBox1.Height, GraphicsUnit.Pixel, imageAttr, imageCallback, imageCallbackData)
End Sub
|
|
|
|
|
Of course it doesn't resize the image. You are taking a portion of the watermark image the same size as the picturebox and draw that onto an area that is the same size as the picturebox.
---
b { font-weight: normal; }
|
|
|
|
|
Yes! you are right about it however I am dealing with a streched image. The actualy size of the image is greater than the Picturebox width and height. It is the problem. I want to draw the large image withing the with and height of Picturebox width and height. When I try to do that, it is getting the portion of the image.
Probably, I am making a mistake if you know the point, please drop me a few lines of sample code...
Appreciated! Thanks
|
|
|
|
|
Read my previos post again, and take a look at the parameters you use when drawing the image. You will se that you are taking only a part of the watermark image, just as I said.
If you want to draw the entire image, you have to specify the size of the entire image, not a portion of the image the size of the picture box.
---
b { font-weight: normal; }
|
|
|
|
|
Yes! you were right! It is working now!
Thanks a lot!
|
|
|
|