|
All you have to do is look at thousands of code samples on MSDN. Most examples are in both languages, supplying you with quite a large Rosetta Stone to translate between the two.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Despite a signifigant amount of research I have yet to be able to crack this one: I Need to be able to adjust the amount of items displayed in the listbox of the combobox - i.e. sometimes 4, sometimes 24, sometimes in between. I've noticed the windows API has a CB_SETDROPPEDWIDTH - but cannot find an equivilant for height (CB_SETITEMHEIGHT sets individual item height - doesn't adjust the listbox size). If it cannot be done through API calls (and i'm beginning to think it can't) then how? If it needs to be painted I would appreciate a brief example if possible?
thanks much
|
|
|
|
|
ComboBox1.MaxDropDownItems should work in vb.net, in vb6 there is not a corresponding function, and in the api there is only a function to find out what the size and position of the dropdown CB_GETDROPPEDCONTROLRECT. You might look into creating a custom control in vb.net expose it to com and use it in your vb app.
Sorry I don't have anything more concrete, maybe someone else does.
|
|
|
|
|
Much Thanks - It is indeed a VB6 project. I suppose that means my only options are to create the vb.net control or to manually paint the control in VB6?
|
|
|
|
|
Thats what I think, someone else may have another idea though.
|
|
|
|
|
Hey everyone,
I've got a webpage that has a selfmade webusercontrol.
That webusercontrol dynamically creates (at this moment only) a label control, a calendar control and a textbox control, depending on how many items I give the control through a Session.
So far so good, for every item in Session a set of these controls is created and added to the page.
They display nicely.
*I hear the collective going "BUT?"*
Ah yes, there's a "but".
What I want to do, is fill the textbox of a set with the selected date of the calendar object of THAT set.
But there are (in this example) two calendar objects.
NOTE: (I have to add the calendar objects dynamically as I don't know how many date type parameters will be required in the near future)
How can I get the selectionchanged event from one of the calendar, so that the control "knows" it's from that calendar and fill the correct textbox that belongs to that calendar ?
Don't forget, all the controls are being generated at runtime in a webusercontrol, which means that somehow I have to create dynamic eventhandlers that "knows" which calendar object had the selectionchanged event and "knows" which which textbox object to set the text of.
Code in VB.NET please, not ASP.NET.
Everything is being done in the code behind, which is VB.NET.
Some help would be greatly appreciated.
|
|
|
|
|
Create your calender control using withevents, create a sub with the same signature as the selection changed event, use addhandler controlname.eventname, addressof yourEvent
|
|
|
|
|
If I use a withevents declaration, I end up with only one calendar on the resulting page.
Seems as though it overwrites the first one.
Perhaps because it uses a global identifier within the control instead of one contained in a sub?
|
|
|
|
|
You don't need withevents to add an event handler at runtime. Just declare it like you have been but add the handler as suggested when you create each control.
|
|
|
|
|
That works like a charm, except...
How do I set the dynamic txtCalendar.text if it's not globally declared?
How can I find the dynamicaly declared textbox and set the text value?
Code so far:
<br />
Public Class ListReportParametersControl<br />
Inherits System.Web.UI.UserControl<br />
<br />
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim intCounter1 As Integer<br />
Dim strParamValue As String<br />
Dim arrSessionParams() As String = Session("ReportParams").ToString.Split(",")<br />
Dim arrTempTypeNValue() As String<br />
<br />
For intCounter1 = 0 To UBound(arrSessionParams)<br />
arrTempTypeNValue = arrSessionParams(intCounter1).ToString.Split(":")<br />
Select Case arrTempTypeNValue(0)<br />
Case "CALENDAR"<br />
SetCalendar(arrTempTypeNValue(1))<br />
ReDim Preserve arrControls(intCounter1)<br />
arrControls(intCounter1) = arrTempTypeNValue(1).ToString<br />
End Select<br />
Next<br />
End Sub<br />
<br />
<br />
Public Sub SetCalendar(ByVal CalendarID As String)<br />
Dim lblCalendar As New Label<br />
lblCalendar.Font.Name = "Verdana"<br />
lblCalendar.Font.Size = FontUnit.Parse("10")<br />
lblCalendar.ID = "Label" & CalendarID<br />
lblCalendar.Text = CalendarID<br />
<br />
Dim myCalendar As New Calendar<br />
myCalendar.Font.Name = "Verdana"<br />
myCalendar.Font.Size = FontUnit.Parse("10")<br />
myCalendar.ID = CalendarID<br />
myCalendar.EnableViewState = True<br />
myCalendar.TodaysDate = System.DateTime.Today<br />
myCalendar.VisibleDate = System.DateTime.Today<br />
myCalendar.TitleFormat = TitleFormat.MonthYear<br />
myCalendar.SelectionMode = CalendarSelectionMode.Day<br />
myCalendar.NextPrevFormat = NextPrevFormat.CustomText<br />
myCalendar.TodayDayStyle.BackColor = System.Drawing.Color.Red<br />
myCalendar.OtherMonthDayStyle.BackColor = System.Drawing.Color.FromName("LightGray")<br />
AddHandler myCalendar.SelectionChanged, AddressOf myCalendarSelectionChanged<br />
<br />
Dim txtCalendar As New TextBox<br />
txtCalendar.Font.Name = "Verdana"<br />
txtCalendar.Font.Size = FontUnit.Parse("10")<br />
txtCalendar.ID = "Textbox" & CalendarID<br />
'txtCalendar.Text = myCalendar.UniqueID.ToString<br />
<br />
Me.Controls.Add(lblCalendar)<br />
Me.Controls.Add(myCalendar)<br />
Me.Controls.Add(txtCalendar)<br />
End Sub<br />
<br />
Public Sub myCalendarSelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)<br />
'Does nothing, yet.<br />
Dim strSenderID As String<br />
Dim strSenderType As String<br />
<br />
strSenderType = UCase(sender.GetType.Name)<br />
strSenderID = sender.ID<br />
<br />
Select Case strSenderType<br />
Case "CALENDAR"<br />
<br />
End Select<br />
<br />
End Sub<br />
<br />
End Class<br />
What do I put in the Case "CALENDAR" ?
It doesn't know txtCalendar...
Any suggestions?
|
|
|
|
|
The quickest fix I can think of is a hashtable. Use the calander object as the key and the textbox will be the value. Declare the hashtable globally and when you create a new 'control group' add the new value.
'Declare globally
dim hash as new hashtable
'In the SetCalander method
hash.add(myCalendar, txtCalendar)
'In the selectionchange event
'This will give you a reference to the appropriate textbox
dim txt as textbox = hash(sender) This should work. It may not be the best solution but it was the quickest fix I could think of.
|
|
|
|
|
You guys are AWESOME...
Total team effort.
I thank M-Hall and Twofaced for their assistance.
|
|
|
|
|
Hi there,
I have a windows application and I need to show some pictures that stored in the server. PictureBox could not show these files and I tried impersonation. But it still throws exception saying 'Unauthorized user'. How can I make the picture box show these images? Thanks a lot...
(I have to write image address like; 'http://server/images/image.jpg'
Savas
|
|
|
|
|
If this is a local server it would be "\\server\images\image.jpg".
Cleako
|
|
|
|
|
Images directory is a virtual directory and I don't know where it is. Actually this is a part of web application (but windows application). So I have to write 'http://server/images/'
Savas
|
|
|
|
|
Ahhh, ok. Well in that case the IIS is most likely what is preventing you from accessing the location. You will either need to adjust the permissions of the directory or IIS in order to get this to work.
Cleako
|
|
|
|
|
Hiya
Does anyone know how to download information from Exchange server?
Not the best way to ask a question but what i'm trying to do is retreive all the information from the shared calander in Outlook.
E.g. Ger - Meeting
i need to get this information in a database
Does anyone have any ideas???? Please?
You are you and I am I. So who is that?
|
|
|
|
|
Hi.
I have a VB NET application that connects to SQL Server and save some data.
When is executed from Windows is OK, but when I try to execute it from VBA (in this case, an Outlook Macro) I get several exceptions.... Like:
... "an error has ocurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections"...
Or some other Cast Exceptions...
I've tried with Shell, or the ShellExecute API....
What I'm doing wrong?
PD: Sorry for my English...
|
|
|
|
|
Are you trying to run this application on a server that doesn't have anyone logged in? The error you gave usually happens when you can not reach the sql server. Is there some reason why you wouldn't be able to access the sql server from the PC you are trying to run the VBA script?
Hope that helps.
Ben
|
|
|
|
|
Hi Kubben.
The application is in the same server as the SQL Server.
In fact, when I run the application in that server from the "Run" command on Windows, it runs perfectly. Is only when is executed from the Outlook Macro (in the same server) when I get the exception.
|
|
|
|
|
So you are logged in when the macro gets run? If the macro is getting run when no one is logged in, I can see where you could be having some problems.
I am starting to wonder if you need a entry in your hosts file on that PC.
C:\windows\system32\drivers\etc\hosts
You put in that computers IP address and the sql server name.
DNS should work to find the sql server, but it may not work since you are already at the correct sql server.
Anyway just some thoughts.
Hope it helps.
Ben
|
|
|
|
|
Yep. I'm logged in when I run the macro, and I have that server on my DNS.
The problem is not only when connecting to SQL Server, also, when I try to CAST "TRUE" (String) to TRUE (Boolean value) I get a Cast Exception. But that only happens when the application is running INSIDE the Macro.
Thanks anyway kubben.
|
|
|
|
|
If you don't want to have to cast the value you can just the Boolean in from .net and use a bit field in SQL as 0 or 1. I have done that a lot. Anyway, just another idea.
Ben
|
|
|
|
|
I don't know if I have to implement Interop to run my .NET Application in VBA:
ON THE SAME SERVER, LOGGED WITH ADMIN RIGHTS
FROM THE RUN COMMAND ON WINDOWS
"X:\MyPath\VBNETAPP.exe" "Param1" -> It runs fine.
FROM VBA (Outlook Macro)
Call ShellExecute(1, "", "X:\MyPath\VBNETAPP.exe", "Param1", "", 1) -> SQL Server AND Cast Exceptions.
|
|
|
|
|
If you are getting a cast exception, it must mean that your boolean value in your string "true" and "false" is not getting properly set. The only way you would get an exception is if the string is coming across as "" which wouldn't cast to a boolean. I am guessing that your parameters that you are passing into your exe are working different. when you call it from the run command it works as expected. I am wondering if the parameters that are getting passed in from the ShellExecute are adding some addional parameters so you are off by one. I would put a MessageBox.Show( in your form load to see what your input parameters are.
Hope that helps.
Ben
|
|
|
|