|
A***** wrote: System.Web.Mail.SmtpMail.SmtpServer = ""
Sorry, I missed this line before. You MUST specify an SMTP server to use, either by IP address or by a valid DNS name. You cannot send mail without one.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for the help, amaneet and dave.
|
|
|
|
|
Alright, basically I am trying to create a function that does the following:
The user has a rank
The possible ranks a user can have are stored in an array ("RankTree()")
The Public Sub in the class is called Promote(Byval Position As String)
My problem is that I'm trying to make the sub find the index of the user's rank in RankTree, then move foreward one index, and set the user's Position (Dude.Position) to the next rank in the array.
How do I go about doing this?
|
|
|
|
|
Diagathon wrote: The possible ranks a user can have are stored in an array ("RankTree()")
Why is this an Array? Why couldn't you use an Enum?
Diagathon wrote: The Public Sub in the class is called Promote(Byval Position As String)
My problem is that I'm trying to make the sub find the index of the user's rank in RankTree
All you have to do is enumerate (For i=0 to ...) the string (I'm assuming they're strings!) in the array and check the current Position to each one in the array. When you find it, I contains the index. All you have to do is increment it.
This problem would probably be better suited for an Enum...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I'll suggest using a LinkedList. Here is an example:
First define a class to hold your object.
Public Class Dude
Public _Name As String
Public _Position As Integer
Public Sub New(ByVal Name As String, ByVal Position As Integer)
_Name = Name
_Position = Position
End Sub
End Class
Then in your main app, define the LinkedList to hold these individual objects.
Dim MyDudes as New LinkList(Of Dude)
You can add items to this several ways:
MyDudes.AddFirst(NewDude)
MyDudes.AddAfter(PreviousDude,NewDude)
MyDudes.AddBefore(BeforeDude,NewDude)
MyDudes.AddLast(NewDude)
There are Find Methods, and Remove methods that can easily help with what you need.
Hope this helps!
~ CodeDoctor ~
|
|
|
|
|
Hi,
I am new to VB.net and am writing my first little application that will print a series of images from a data grid to a printer (in this a PDF driver).
If it does one page then it works, but I want it to print onto seperate pages, then it either prints the first page spot on, but then nothing else, or just prints the next set of images over the previous ones. I think I have tried all version of HasMorePages but I may just have it in the wrong place....
Any help would be appreciated....
Thanks
Jamie
Private Sub Test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Test.Click
Try
AddHandler PrintGraphicControl.PrintPage, AddressOf Me.GraphicPrint1
PrintGraphicControl.Print()
Catch ex As Exception
MsgBox("Test Error" & ex.Message)
End Try
End Sub
Private Sub GraphicPrint1(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim i As Integer
Dim rCnt As Integer 'row count
Dim cLeft = e.MarginBounds.Left
Dim cTop = e.MarginBounds.Top
Dim pLength = e.MarginBounds.Bottom - e.MarginBounds.Top
Dim iName As String
For i = 1 To DataGridView1.RowCount
rCnt = rCnt + 1
Next
For i = 1 To rCnt
DataGridView1.CurrentCell = DataGridView1(curColumn, i - 1)
iName = imgPath & (DataGridView1.CurrentCell.Value) & ".jpg"
Try
Dim rDest As New RectangleF(cLeft, cTop, 0, 0)
Dim printFont As Font = New Font("Arial", 10, FontStyle.Regular)
If Image.FromFile(iName).Width < e.MarginBounds.Width Then
'-- Set to bitmap size if bitmap is smaller than paper
rDest.Width = Image.FromFile(iName).Width
rDest.Height = Image.FromFile(iName).Height
Else
'-- Set to paper size if bitmap is larger than paper
'-- Scale height to retain proportions
rDest.Width = e.MarginBounds.Width
rDest.Height = CType(rDest.Width * (Image.FromFile(iName).Height / Image.FromFile(iName).Width), Single)
End If
If pLength < cTop + rDest.Height + (3 * printFont.GetHeight(e.Graphics)) Then
cLeft = e.MarginBounds.Left
cTop = e.MarginBounds.Top
e.HasMorePages = True
Else
e.HasMorePages = False
End If
e.Graphics.DrawImage(Image.FromFile(iName), rDest, Image.FromFile(iName).GetBounds(GraphicsUnit.Pixel), GraphicsUnit.Pixel)
'-- Draw timestamp
e.Graphics.DrawString(Now.ToString, printFont, Brushes.Black, rDest.Left, rDest.Top + rDest.Height + printFont.GetHeight(e.Graphics))
cTop = cTop + rDest.Height + (3 * printFont.GetHeight(e.Graphics))
Catch
End Try
Next i
End Sub
|
|
|
|
|
From what I can see, or more accurately what I can NOT see, in you're code is any support for getting the page number that is currently being printed and using that in some way as an index into what you're supposed to be printing.
What your GraphicPrint1 handler is called, it's job is to print the single page that is being worked on. Nowhere in your code are you tracking what is on the current page, what you have printed, or what you have remaining to be printed.
In the example that I'm assuming you used to model this code from, in the PrintDocument.PrintPage event documentation on MSDN, notice that the StreamReader at the top of the code (declared in class scope) is what is tracking what was printed and what remains to be printed:
Public Class PrintingExample
Inherits System.Windows.Forms.Form
Private streamToPrint As StreamReader
...
Private Sub printButton_Click(sender As Object, e As EventArgs)
Try
streamToPrint = New StreamReader("C:\My Documents\MyFile.txt")
...
Finally
streamToPrint.Close()
End Try
End Sub
Private Sub pd_PrintPage(sender As Object, ex As PrintPageEventArgs)
Dim line As String = Nothing
...
line = streamToPrint.ReadLine()
...
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
OK. So how does the PrintPage handler know when there is no more text to print? The streamToPrint is defined in class scope, so it doesn't lose it's place inside the PrintPage handler when everything else in there goes out of scope and is destroyed. That StreamReader is what is keeping track of what has been printed and what still needs to be printed. Notice that the StreamReader is created and destroyed in the Button_Click event, not in the PrintPage event!
Your code has to do something similar. It has to have class scoped variable that keep track of what has been printed or what still needs to be printed, like an index number into an array or collection that your GraphicPrint event has to advance to the next image and check to see if it still has more images to go.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Many thanks Dave... I think I misunderstood quite how it was supposed to work!
Thanks again!
|
|
|
|
|
Yeah, I've found that describing how Printing and DataGrid's work is a bit of large undertaking when someone doesn't know the basics of programming or OOP. You, on the other hand, seemed to have a good enough grip on them, which makes the process a whole lot easier to describe!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I'm quite new to programming and VB.NET, so Idon't know if this is really obvious.
I ran my Rich Text Editor (using Telerik R.A.D. RibbonBar and your own ExtendedRichTextBox), and I got the following error:
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
Stack trace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190<br />
at WindowsApplication1.My.MyProject.MyForms.get_frmMain()<br />
at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Documents and Settings\lucas\My Documents\Visual Studio 2005\Projects\LucasToolsEditor\My Project\Application.Designer.vb:line 35<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br />
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()
Thanks.
|
|
|
|
|
Sorry I did not mention this, but my RibbonBar has disappeared. Kind of. When I click on its area, it shows up in the properties window, but it is just blankon the form.
Sorry.
|
|
|
|
|
You're probably going to have to remove the RibbonBar from your project, then go through the code files for your form and remove all mention of the RibbonBar. This should let you reopen the form in the Designer. If it does, then you can try to readd the RibbonBar and resetup the properties you had setup for it.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks, I'll just try that now.
|
|
|
|
|
Hi,
I want to access database which is kept on website in database folder.
Anybody could help me please? How to connect this database? What should be
connectionstring for it with detail code? i am developing it in Vb.net 2005 with MS Access database.
I am beginer for vb.net.
If possible please send me example.
Database path is like: http://XXX.XXX.XXX.XXX/abc/database
How to write the connection string; Also the database is password protected;
Kiran Sajanikar
-- modified at 9:14 Wednesday 11th April, 2007
|
|
|
|
|
You can't do that unless you want to open up a HUGE security hole. Most web sites, as I hope yours as well, will not allow you to write to folders over HTTP. You need to be able to open the database with both Read AND Write permissions to use it.
You can, however, still use the database. But, you have to write a web service, which runs on HTTP, to do all the database work for your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanx for your reply,
But as I told you that I am beginer to vb.net; so I am bit confused. Now how should i proceed to solve my problem. Give me some hints so I can strat my project.
Kiran Sajanikar
|
|
|
|
|
I already told you what you have to do.
It's either expose all the functionality of your database through a Web Service you have to write or you switch to a database engine that supports communication over TCP/IP, like SQL Server or mySQL.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Once again thnx for immediate reply,
I got your point.
I will Work on it now.
Kiran Sajanikar
Software Engineer
CleverBIT softwares.
Pune.
|
|
|
|
|
Hi
i am facing a poblem in using the api
the api is
Private Declare Function GetProfilesDirectory Lib "userenv.dll" Alias "GetProfilesDirectoryA" (ByVal lpProfileDir As String, ByVal lpcchSize As Long) As Boolean
and the code is
Dim sBuffer As String
Dim strPARENT As String
sBuffer = ""
GetProfilesDirectory(sBuffer, 255)
when the control comes to to the execution of the code line
GetProfilesDirectory(sBuffer, 255)
there occurs the following error
Attempting to Read or write the protected memory
this is often an indication that other memory is corrupt.
please help.
|
|
|
|
|
I take it you're looking for something to give you the path to the Documents and Settings folder??
You don't need the API to do it:
Imports System.IO
Dim profilesPath As String
profilesPath = Path.GetDirectoryName(Environment.GetEnvironmentVariable("USERPROFILE"))
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi! All,
Please help me to sort out my problem of copying files from a folder of FTP site. I am using Inet Control for this purpose but it is giving an error that "Unable to Connect to remote host." The FTP site which I want to access need userid and password, which I am providing but still no result. Please help me how to resolve this problem.
Virendra
|
|
|
|
|
First, are you using VB6 or VB.NET and which version of VB.NET?
Next, let's see the code you're using to connect to this FTP server and get the file.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
hi! Dave,
I am using VB6. Main Code is as follows
Dim MyFTP as FTP
With MyFTP
'
' Initialize the FTP connection.
'
If Not .FTPInit(gsServer, gsUser, gsPswd, 0, 0, "", sError) Then
GoTo cmdReceiveError
End If
'
' Transfer the file(s)
'
If bSingleFile Then
Call .FTPGet(gsLocalDir, sFileType, gsFTPDir, sError)
If sError <> "" Then GoTo cmdReceiveError
Else
Call .FTPGetAll(gsLocalDir, sFileType, gsFTPDir, sError)
If sError <> "" Then
sMsg = sError
GoTo cmdReceiveError
End If
End If
'
' Close the connection.
'
Call .FTPClose
End With
lblStatus = sMsg
'
' cleaning.
'
Set MyFTP = Nothing
Dim bFiles As Boolean
Dim sFileName As String
Dim ofile As File
Dim ofiles As Files
bFiles = False
FTPPutAll = False
On Error GoTo FTPPutAllError
Set ofiles = fso.GetFolder(sLocalFolder).Files
For Each ofile In ofiles
sFileName = UCase$(ofile.Name)
If InStr(1, sFileName, UCase$(sFileNameString)) > 0 Then
bFiles = True
If Not FTPPut(sLocalFolder, sFileName, sFTPFolder, sError) Then
Exit Function
End If
End If
Next
Set ofile = Nothing
Set ofiles = Nothing
If bFiles Then
FTPPutAll = True
Else
sError = "No files found."
End If
Virendra
|
|
|
|
|
OK. I have no idea what the "FTP" class is, but it's not the Internet Transfer Control. If you're not using the ITC, you'll have to go back to the people that wrote the class you're using for support on it. I have no idea who that is or where the library came from. There's not enough information to track that down either.
The Internet Transfer Control has problems with it when using a Username and Password, as documented here[^].
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi every one,
I want to extract first word from a string (e.g. ASD XYZ)
then i want ASD to be stored in a separate variable.
Is there a vb function to do.
Thanx and rgds,
Ahmad
|
|
|
|
|