|
Okay - you'll want a Select Case block then. You could, for example, modify the SendAMessage sub to inspect the location and set the .To message property accordingly:
Public Sub SendAMessage(sLocation as string)
dim Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
'--set the .To property depending on the location
Select Case sLocation.ToUpper()
Case "NORTH AMERICA": Message.To = "naRecipient@test.net"
Case "EUROPE" : Message.To = "europeRec@test.net"
'... other cases ...
Case Else : Message.To = "defaultRec@test.net"
End Select
'... other code as before ...
End Sub
|
|
|
|
|
I have a two form project. Form1 has one button on it with two lines of code:
Dim f_form2 As New Form2
f_form2.ShowDialog()
Form2 reads in a .JPG from SQL Server and displays the .JPG in a picture box on Form2. All this works great UNTIL I close Form2 and call it a second time. Form2 blows up with the following message:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file "C:\pic.jpg" because it is being used by another process.
If I close down the whole app and restart it, it's fine until the second call to Form2, so I'm obviously not releasing something correctly but don't know what to try. Help!
Thanks in advance.
*** here's the code ****
<br />
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
Dim fs As New FileStream("C:\pic.jpg", FileMode.Create, FileAccess.Write) 'blows up here second time form is called<br />
Dim bw As New BinaryWriter(fs)<br />
<br />
Dim Buffersize As Integer = 16384<br />
Dim Outbyte(Buffersize - 1) As Byte<br />
Dim retval As Long<br />
Dim startindex As Long = 0<br />
Dim actualsize As Integer<br />
<br />
Dim ConString As String<br />
ConString = ("Persist Security Info=False;Integrated Security=SSPI;Data Source=(local);Database=db")<br />
<br />
Dim strSQLCommand As String<br />
strSQLCommand = "select blob_segment from blob where picid = 574739053"<br />
<br />
Dim Connection As New SqlConnection(ConString)<br />
<br />
Dim Command As New SqlCommand(strSQLCommand, Connection)<br />
<br />
Connection.Open()<br />
Dim Reader As SqlDataReader = Command.ExecuteReader(CommandBehavior.SequentialAccess)<br />
<br />
actualsize = 0<br />
<br />
Do While Reader.Read<br />
startindex = 0<br />
<br />
retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
<br />
Do While retval = Buffersize<br />
MsgBox(Str(Buffersize))<br />
bw.Write(Outbyte)<br />
bw.Flush()<br />
startindex += Buffersize<br />
retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
Loop<br />
<br />
bw.Write(Outbyte, 0, CInt(retval))<br />
bw.Flush()<br />
fs.Flush()<br />
bw.Close()<br />
fs.Close()<br />
<br />
Loop<br />
<br />
Reader.Close()<br />
Connection.Close()<br />
<br />
PictureBox1.Image = Image.FromFile("c:\pic.jpg")<br />
<br />
End Sub
|
|
|
|
|
VB is not my thing, but it looks like your file isn't being closed correctly.
Try moving these lines:
bw.Flush()
fs.Flush()
bw.Close()
fs.Close()
outside the loop.
I don't quite know what your code is supposed to do, but I'm not sure if there are other errors because I'm not really that familiar with VB, but the opening of those objects is not occuring inside the loop, so the closing typically shouldn't be done inside the loop either.
And actually, you can drop all those calls except bw.close(). Calling bw.Close() will automatically flush and close the underlying stream.
|
|
|
|
|
Thanks for your reply.
I played with this a bit this weekend, it seems to be a rights issue. The following code blows up with the same error.
"Additional information: The process cannot access the file "c:\mypic.jpg" because it is being used by another process."
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
File.Copy("c:\blue.jpg", "c:\mypic.jpg", True)<br />
<br />
PictureBox1.Image = Image.FromFile("c:\mypic.jpg")<br />
<br />
PictureBox1.Refresh()<br />
<br />
File.Copy("c:\green.jpg", "c:\mypic.jpg", True) <<< blows up here <br />
<br />
PictureBox1.Image = Image.FromFile("c:\mypic.jpg")<br />
<br />
PictureBox1.Refresh()<br />
<br />
End Sub
|
|
|
|
|
In Microsoft Project, a task's timeline can be extended by dragging the end of the bar in the Gantt chart. Is there a way to do this with the PjGrid.ocx?
|
|
|
|
|
I was trying to create my own Browser Helper Object using C#. I have made dll but I don't exactly know how to make the setup file.
I have included:
1)the dll for the BHO
2)the XML file that i am using
in the application folder in the file system editor
but i dont know what to change in the registry editor. im guessing i have to change the "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects"
but does that mean i have to create this since it isnt already in path in the registry editor? and what do i put in this place, is it my GUID?
help would be much appreciated
abhi
ps. I was using Regasm but recently is has come up with a:
"'Regasm' is not recgonized as an internal or external command, operable program or batch file"
error in the DOS prompt and the .NET 2003 prompt
any ideas what this means or why it would do this?
|
|
|
|
|
Hi,
I have a question: How can I set the datasource of a datagrid by using codes? I've been using the properties on the right side to set it.
Then I also have a problem... Why is it that whenever I use:
adodc1.recordset.addnew
ado.Recordset.Fields(0) = Trim(txtname)
ado.Recordset.Fields(1) = Trim(txtage)
ado.Recordset.Update
the data that I save in a database is automatically displayed on the datagrid. But if I use:
Set adocon = New ADODB.Connection
Set adorset = New ADODB.Recordset
adocon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "dbnames.mdb"
adorset.Open "Table2", adocon, adOpenKeyset, adLockOptimistic
adorset.AddNew
adorset.Fields(0) = Trim(txtname)
adorset.Fields(1) = Trim(txtage)
adorset.Update
the data that I save on a database don't appear automatically and it would only appear once I unload and reload my form or if I use
DTG.Columns(0) = gadors.Fields(0)
DTG.Columns(1) = gadors.Fields(1)
DTG.Columns(2) = gadors.Fields(2)
DTG.Columns(3) = gadors.Fields(3)
wherein the problem is that it overwrites the first record on a datagrid and once I unload and reload, that's the only time that the new record would be placed at the end.
I can't use the movenext and moveprevious properly as well whenever I use this type of setup.
Thanks....
|
|
|
|
|
i want to retrieve the hardware details of my system like the mouse connected to my system, the keyboard details
|
|
|
|
|
Do you mean through VB or just visualy through windows?
Second option: Click Control Panel, System, Hardware Tab, then Device Manager
Later
|
|
|
|
|
In code, you could use the System.Management namespace and WMI.
RageInTheMachine9532
|
|
|
|
|
thank you i will try it out
|
|
|
|
|
In code, you could use the System.Management namespace and WMI.
RageInTheMachine9532
|
|
|
|
|
I've created a crystalviewer control on the form. now I want to scroll the CR control by mouse wheel.
I use the MOUSE_WHEEL(event) to get the value of e.delta. but should i do when e.DELTA=120 or -120 to scroll the crystalviewer.;)
got another question but this one is a hell for me.
|
|
|
|
|
I wonder why streamwriter.writeline does not do what it is supposed to do? For example, in the following code, I try to write 5000 lines to a file, then I found after writing about 4800 lines, the precedure exits without any error. This did not caught my attention until the other day I tried to write some database records to a text file and it never finish writing up all of the records. However, response.write would faithly do the work for me. Why?
Private Sub testSW()
Dim i As Integer
Dim sw As StreamWriter
sw = New StreamWriter("c:\test.txt")
For j = 1 To 5000
sw.WriteLine(j & " test@test.com")
Next
End Sub
|
|
|
|
|
You need to call Close and Dispose at the end of the sub.
Due to technical difficulties my previous signature, "I see dumb people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
thanks. I am a little dumb, to be honest. Sigh ...
|
|
|
|
|
i require the code which can automatically change screen resolution
Sachin323
|
|
|
|
|
Automatically change the resolution based on what?
Changing the screen resolution is a concept best left to games, in which case you would use either DirectX or OpenGL. Changing it in a normal Windows app is VERY bad practice.
RageInTheMachine9532
|
|
|
|
|
Hi, EveryBody,
I want to display pictures stored in a database. First I use the following code(VB6) to save the picture to the database:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stream As New ADODB.stream
Set cnn = New Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\test.mdb;"
cnn.CursorLocation = adUseClient
cnn.Open
Set rst = New Recordset
rst.ActiveConnection = cnn
rst.Open "t1", cnn, adOpenKeyset, adLockOptimistic
rst.AddNew
rst!p_name = "dd"
stream.Type = adTypeBinary
stream.Open
stream.LoadFromFile "H:\pp.jpg"
rst!pic = stream.Read
Set stream = Nothing
rst.Update
cnn.Close
------------------------------
and then I use the following code(ASP) to display the image:
<%
Dim cnn
Dim rs
' Clear existing HTTP header info
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' Set the HTTP header to an image type.
Response.ContentType = "image/JPEG"
cnnPubs=getdbconn() ' the function return the db connection
set rs=server.CreateObject("adodb.recordset")
rs.Open "SELECT FROM t1where id=1",cnn
Response.BinaryWrite rst("pic")
Response.End
%>
and I use to show the image.
the first(vb) code works well.
but I alway can not display the image, I just got a image like red X.
please help me to solve the problem.
Thanks a lot!!!
Best!
Alan
|
|
|
|
|
I have to be produce a zoomed in image of a picture that is displayed. in a seperate box to the reg size image. I have the cooords and dimensions of the area that I want, but I cannot figure out how to either extract part of the image or simply copy the image and then zoom in.
This is the AxImgEditLibCtl that I am referring to. I tried to create a graphics object, and use the methods that it provides, but because the initial image that I am using is a .tif like file there is a number of images contained within it, and therefore the graphics class doesn't work (I have tested with simple gif and jpegs and it does work)
If anyone has worked with this class before I would appreciate some input because I have tried for way too long and have only gone in circles.
Thanks
|
|
|
|
|
It would be cool if I cold some how obtain an image or bitmap of the picture that is currently being displayed
|
|
|
|
|
I have a VB6 program that needs to reference the Microsoft Outlook 9.0 Object Library since it will be running on a machine the still uses Office 2000. The machine I want to compile the program under uses Office 2003 which uses the Microsoft Outlook 11.0 Object Library. When compiled under this machine it will not run on the Office 2000 machine because it cannot find the object. Is there a way that I can ad a reference in VB6 to the 9.0 Object library? I can compile under a 2000 machine but I want to avoid that if possible. Thanks!
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
You cna't do it unless the machine you compile the app on actually has Office 2000 on it. Any machine your app runs on would need Office 2000 on it. You referencing any version of the library will not give your app the ability to use any version of Office. The machine MUST have the version of Office that you compiled against.
RageInTheMachine9532
|
|
|
|
|
I had this same problem with using the WORD and EXCEL object libraries. The following example I'll use is with WORD, but you can modify it for your own project.
Dim wA as Object<br />
Dim WordWasNotRunning as Boolean<br />
<br />
Sub Test()<br />
On Error Resume Next<br />
Set wA = GetObject(, "Word.Application")<br />
If Err Then<br />
Set wA = CreateObject("Word.Application")<br />
WordWasNotRunning = True<br />
End If<br />
On Error Goto 0<br />
<br />
<<Insert Code Here>><br />
<br />
If WordWasNotRunning then wA.Quit<br />
Set wa = Nothing<br />
End Sub
This code creates an object and then by using the GetObject/CreateObject opens whichever object library is installed on the machine. The boolean is so that you do not close the Word application if they already had it opened with another document, if you don't do it this way, then you will leave multiple WinWord.exe processes running on the machine and your program will crash after you have initialized it at least once. (MAKE SURE YOU DESTROY THE OBJECTS!!)
HINT:
Design your program first by loading the object libraries for Office so you can debug the program and get the helpful dropdown menus. Then before you compile it, change the code to the code on top and get rid of the library References. I also found out that older versions of office do not use the same constants (i.e. wdStory, etc.), so use the actual values like '6'. Hope that helps.
-Garrett
|
|
|
|
|
Yeah thanks...I found that the CreateObject lets me do "late binding" so that I can reference whatever object library is installed on the machine. I'm not at work so I can't post my code but when I get back on Mon. I may post a little of it. The Outlook object lets my reference folders such as my inbox with numbers like 6 (which is my inbox on my machine) and it compiles and runs fine on my machine that runs Office 2003 without having to reference the outlook obj library. Then I emailed the exe to the guy that sits behind me who runs Office 2000 and when he ran it, it threw a run-time error. I think it has to do with the 6. I tried something like olFolderInbox but then it wouldnt build. I'll have to post some code...
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|