|
Found it!
Using the parentheses is forcing VBA to evaluate the bracketed expression (in this case, your variable Cancel ) and then pass it as ByVal into the subroutine. Ergo the value remains unchanged in the calling sub.
See Matthieu Guindon's solution here [^] for a fuller explanation
|
|
|
|
|
Thanks! I had given up and used a workaround (which actually turned out to have other advantages, so it wasn't all bad). VBA's requirement that you not surround sub/function arguments with parens (unless you make an explicit Call) is always catching me out, since every other language I use require the parens. Fortunately, it mostly affects implicit calls with multiple arguments, where putting in the parens provokes an immediate syntax error in the editor. This case is a particular pain since the bad syntax is not flagged but nevertheless changes the meaning of the call.
|
|
|
|
|
VBScript and VBA require parenthesis around the parameters of functions that return a value.
For functions that don't returns a value, no parenthesis go around the parameter list.
It's the stupidest thing I've ever seen.
On, and you never need to use "Call" to call another function at all.
|
|
|
|
|
1: It's the stupidest thing I've ever seen. I couldn't agree with you more!
2: and you never need to use "Call" to call another function at all. Except when you put parentheses around your parameter list. In which case quote 1 applies
|
|
|
|
|
In the mountain of VB6, VBA, and VBScript code I've written, I've never used 'Call'. It just seemed so COBOL to me, YUK!
|
|
|
|
|
|
I want to Use the following Com Funktion ( From idl File)
[id(2)] HRESULT Request ( [in] long id, [in] BSTR version, [in,out] BSTR sender, [in] BSTR login, [in] BSTR selection, [in, out] BSTR* data , [out, retval] long* retval );
from my Visual Basic Scriot ( Visual Studion 2015) wenn i call my funktion from ma scrip like tis
Private Sub Request_1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Request_1.Click
Dim r As Integer
Dim data As String
Dim ID As String
Dim sender As String
sender = "DatO"
If ID_KS_1.Text <> "" Then
ID = "ID_KS=" & ID_KS_1.Text & ","
sender = "KS_Trifact"
End If
ErrorText.Text = ""
If obj Is Nothing Then obj = CreateObject("NmsTaskDbSv.64Bit_NmsDbData")
'UPGRADE_WARNING: Couldn't resolve default property of object obj.Request. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'r = obj.Request(15101, "1.0", sender, "customerservice/customer", ID & "ACCOUNT=" & Par_1_1.Text, "test")
r = obj.Request(15101, "1.0", sender, "customerservice/customer", ID & "ACCOUNT=" & Par_1_1.Text, (data))
If (r = 0) Then
Result_1.Text = data
Else
ShowLastError()
End If
End Sub
it seams to work but rhe response dues not arrive in the data variablele wenn i make the call j = CreateObject without () lik this
'r = obj.Request(15101, "1.0", sender, "customerservice/customer", ID & "ACCOUNT=" & Par_1_1.Text, data)
i get a type mismatch error ho i have to call Request to get the Data String as answer
Thanks
|
|
|
|
|
You keep saying "VB Script" when the code you posted is NOT VBScript. It's VB.NET. VBScript is a very different language and runtime environment from VB.NET.
If you added a reference to the COM .DLL you're using, you would not have to use CreateObject to create an instance of the class. You could just "new one up".
Dim obj As New 64Bit_NmsDbData
Of course, you'd have to import the namespace for that class at the top of the code.
|
|
|
|
|
Hi everyone, my name is Maurizio and my question is this
In VB I would like to know how to create one or more objects of the same type at run time.
I'll explain:
1) In a form I insert a textbox1 and a button
The purpose of my request is to know how: By pressing this button
It should bring up another textbox and so on.
that's all !!!!
If I remember correctly I used the New function
But it seems that this does not work in vb.
Could you please help me Thanks
Greetings from Maurizio
|
|
|
|
|
The New keyword does work. All it does is create an instance of a type, be it a class or a COM type, or the like.
You create a new TextBox just by "newing one up":
Dim myNewTextBox As New TextBox
You then have to set it's properties, like Top, Left, Height, Width to set the size and position on the Form or in another container.
Then you have to add it to the Controls collection of the container you're adding it to, like your Form:
myForm.Controls.Add(myNewTextBox)
|
|
|
|
|
You can do it like suggested by Dave - the other way could be (perhaps easier to code and to maintain for you) :
- Create the Textbox you want to bring up from the beginning with the Designer.
- Set it's Visible-State to False
- When pressing the Button set it's Visible-State to True.
In this case you are able to make all the relevant connections.
You don't need to modify the Controls-Collection from the Form, catch the Events from the new Control and so on ...
|
|
|
|
|
Thank you to everyone for your interest
But it wasn't the answer I would have expected from experienced people like you.
Thanks anyway
/p.s) But if instead of cloning I asked for a sort of (Textbox) Dynamic with at least 5 possibility of creating (Textbox) on request!
What would have changed?
I'll explain :
If I press the key inserted in the form and I create the first dynamic (Textbox)
How can I go about creating a new one at least five times the same size as the first?
I tried to write something like this; But it is valid only for the first dynamic (Textbox)
Therefore I would miss being able to create all the others every time I press the create button.
Thank you
|
|
|
|
|
|
I just told you how to do it. It is the correct answer based on your own description of what you want to do.
|
|
|
|
|
Perhaps (to make it much easier for us) you should provide your Code-Snipped ...
Sometimes a "Picture" tells more than 1000 words ...
|
|
|
|
|
They all "default" to the same size and location unless you "change" the property's default value at "construction" time or subsequently. Based on your problem description, that's all that "experience" dictates. If your requirements are more complex, you have failed to articulate them; perhaps it needs "reflection"; but that requires "experience".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi
I have created a program that is intended to be used by multiple users (each on their own computer) who access the same SQL database. I have also created a separate updater program to sit alongside the main application. However, I am unsure how to check if there are any users in the main program before the update is run. (This is easy to do on a single user application but not sure on multi-user).
Any help is greatly appreciated
(I am relatively green here so please be kind)
|
|
|
|
|
If you want to update only client application, the number of users connected to the database is not important.
Does updater have to update database too?
|
|
|
|
|
No. The client will be updating the database. It is more an issue of ensuring no users are in the program while the update is running.
If this was a single user prograM then it is easy to check and force a close. I am not sure when there is more than one user (from different computers)
|
|
|
|
|
|
I think what you need to research is the topic of concurrency.
One way to implement this is to have a Modify Date on the primary record.
1) Read the table entry along with the modify date/time.
2) When updating the database, compare the original date/time with the value currently stored, if the date/time has not been changed, then it is OK to perform your update. (Rollback)
During your update you would set the modify date/time to the current date/time. (GetDate() )
Something like that.
|
|
|
|
|
I am sure this is not the best format to ask this question/ have this general discussion.
My project is at the barebones, working on a lot of the basics at the moment. The plan is to have a game completely ran on a userform.
Really the only thing I have kind of figured out is the the key logging to track when the space bar, left, right, up, down arrow keys have been pressed. I have only figured out how to do that if a textbox is the focus. Not the happiest with that at moment. Any thoughts on this is appreciated.
I have done a ton of research to see what is currently out there. A majority of the code I find is ran on a spreadsheet, which becomes the base/map. Taking away the spreadsheet leaves my google searches with not many results.
Something I have thought of is having a userform with multiple textboxes like a spreadsheet. Each textbox would be like one cell on a spreadsheet. Problem with this is that I don't think that would do well once trying too get more advance with the game.
The thing that seems like it will be key is keeping track of the pixels location of every object and creating the game logic from there.
The object of the game really isn't the focus right now. To give an end game for my first problem/"curiousosity on how others would go about it" lets say the game is to have a character dodge incoming missles/objects that would come from any direction straight across the board.
I would post my code but it really isn't much at the moment.
1. Please don't respond with something like "why would you do this in vba" or anything like that. I am well aware that there other languages that would better fit this.
2. Sorry for everything being "scatter brained" this is my first time posting a question after about 2 years of doing multiple projects using vba.
3. If there is a better site or resource to use for what I am trying to do please let me know.
There isn't any direct questions, more so looking to get thoughts and opinons on anything I put out there. Appreciate any feedback!
|
|
|
|
|
In other VB Windows Forms implementations, the KeyDown/KeyUp events on your Form will only work if the Form has the focus. If the Excel sheet has the focus, they will not work.
Also, in order to get those events to work when any control on the Form has the focus, the KeyPreview property on the Form must also be set to true, though, it appears that this doesn't even exist in Excel VBA.
Basically, without a working KeyPreview property, you cannot do what you appear to want to do.
|
|
|
|
|
First, Thank you for engaging in the conversation!
My idea at the moment is to have the spreadsheet hidden as soon as the userform is initiated. That could be from a command button or from the moment excel loades/macros are enabled.
I am thinking that a full screen userform, with an api to keep the userform always on top. Then (idk if this is a thing) an api to keep the userform always in focus?
From there keep a textbox always in focus (assuming hidden or not visible probably) to keep the ability of key logging.
If this is the best road to keep the Ability of logging the arrow keys pressed, maybe have two objects above and below the textbox in the zorder to force the focus back to main key logging textbox?
Any ideas, thoughts, or better work around that you can think of?
|
|
|
|
|
In Excel VBA, there is no such thing as "Always on top", and in Windows, there is no such thing as "Always has focus".
Windows is a shared system. Your app has to play nice with everything else, including the ability to lose focus to another app at any time, no matter which environment you write code in.
The limitations of VBA are going to fight you all the way on this.
|
|
|
|