error in me.show()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I can't seem to make the Me.Show() work

My code is

dim dlgresult as dialogresul

dlgresult=me.show(

The message is : "expression does not produce a value

But if I sue this: dlgresult=Me.ShowDialog(), it works. It's just that I need my form to me modeless

What am I missing here

Thanks :)
 
Hi Ed,
But if I sue this: dlgresult=Me.ShowDialog(), it works.

Does this works, what did you more on your form to create this.

You shows a form itself again as a dialog withouth instancing a new one?

Tell something more what you want to archieve.

Cor
 
Hello,

Me.Show() doesn't return a value this is because its modeless and execution
continues without waiting.

Just try Me.Show() on its own.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:[email protected]
-
 
Oh I see. The problem now is that i need to return a value....to make it clearer, here's the rest of the code: (sorry for not showing this earlier

dim dlgresult as dialogresul

dlgresult=me.show(

select case dlgresul
Case DialogResult.Cance
-----right code her

Case DialogResult.Chang
-----right code her

Case DialogResult.Ignor
-----right code her

end selec

As you said, Me.Show doesnt return a value, how can i make my code above work? Is there a workaround? Thanks :

Hello

Me.Show() doesn't return a value this is because its modeless and execution
continues without waiting

Just try Me.Show() on its own

Regard
Simon Jefferie
Tools Programmer, Headfirst Production
mailto:[email protected]
 
Hi Cor

What I'm doing here is a spell check routine. The spell check form will appear if it sees a misspelled word. If it finds one, then it will run this code

-----start code----

startPos = InStr(1, ctrl.Text, strWord
wordLength = Len(strWord
ctrl.Select(startPos - 1, wordLength
ctrl.Focus(

dim dlgresult as dialogresul
dlgresult=me.show(

select case dlgresul
Case DialogResult.Cance
-----right code her

Case DialogResult.Chang
-----right code her

Case DialogResult.Ignor
-----right code her

end selec
----end code---

Basically, the main reason why i want the spell checker form to be modeless is because after finding a misspelled word, it will highlight that word. If the spell checker form is modal then the focus will always be on the spell checker form, thus the highlight won't be shown in the main form

The problem now is that dlgresult=me.show won't work, it only works if it's dlgresult=me.showdialog(). How can i make it work? Thanks :

edga

Hi EdDoes this works, what did you more on your form to create this
You shows a form itself again as a dialog withouth instancing a new one
Tell something more what you want to archieve

Co
 
On your SpellCheck form, when the Ok Button (or any button for that matter)
is clicked just do

Me.DialogResult = --- whatever ---

then hide the form...

thats the exact same thing show dialog does...


Ed said:
Oh I see. The problem now is that i need to return a value....to make it
clearer, here's the rest of the code: (sorry for not showing this earlier)
dim dlgresult as dialogresult

dlgresult=me.show()

select case dlgresult
Case DialogResult.Cancel
-----right code here

Case DialogResult.Change
-----right code here

Case DialogResult.Ignore
-----right code here

end select

As you said, Me.Show doesnt return a value, how can i make my code above
work? Is there a workaround? Thanks :)
 
I changed my code to

Me.Show(

select case me.dialogresul
Case DialogResult.Cance
-----right code her

Case DialogResult.Chang
-----right code her

Case DialogResult.Ignor
-----right code her

end selec

there are no more error messages. The problem now is that the code will continue executing after Me.Show without waiting for an event on the spell check form. How can I make it stop after the Me.show? Is it possible? What i want to happen is somehow mimic the ME.ShowDialog(), but unlike it, i can switch forms (modeless).

Thanks

Ed
 
Ed,
It sounds like you are confusing returning a single value once and returning
a value multiple times.

The point behind a modeless form is to allow returning a value multiple
times. The easiest way to return a value multiple times is to have your form
raise an event.

I would recommend having the dialog raise an event when the parent form
needs Cancel, Change, or Ignore.

You then either need to use a WithEvents variable or AddHandler &
RemoveHandler to handle the events the dialog raises.

Hope this helps
Jay

Ed said:
I changed my code to:

Me.Show()

select case me.dialogresult
Case DialogResult.Cancel
-----right code here

Case DialogResult.Change
-----right code here

Case DialogResult.Ignore
-----right code here

end select

there are no more error messages. The problem now is that the code will
continue executing after Me.Show without waiting for an event on the spell
check form. How can I make it stop after the Me.show? Is it possible? What i
want to happen is somehow mimic the ME.ShowDialog(), but unlike it, i can
switch forms (modeless).
 
Ed said:
I changed my code to:

Me.Show()

select case me.dialogresult
Case DialogResult.Cancel
-----right code here

Case DialogResult.Change
-----right code here

Case DialogResult.Ignore
-----right code here

end select

there are no more error messages. The problem now is that the code
will continue executing after Me.Show without waiting for an event on
the spell check form. How can I make it stop after the Me.show? Is it
possible? What i want to happen is somehow mimic the ME.ShowDialog(),
but unlike it, i can switch forms (modeless).

That's why I asked /when/ it should return a value.
 
When the spell check form appears (that is when the Me.Show executes), It should wait for a response from the spell check form as to what button is to be clicked. For example, if the Cancel button is click it should run this part of the code

select case Me.DialogResul

case DialogResult.Cance
-------code to be execute

end selec

I'm sorry for the confusion but what i really meant was that it will be waiting for an event (not returning a value)

ed
 
Here is an alternative.

How about you add an event handler to the LostFocus event of the form. Now,
understand this is going to be some pretty extensive work, but I think it
will solve your problem.

Then on lost focus you would set the focus back on the form. Here is where
it gets tricky, because say a user wants to click on another application,
however, with the spell check open and the lost focus event (or deactivated
whatever) we can't do this "as-is"

So then when you lose focus, I think you can use the API to get the next
window that is being selected, get its handle, compare that handle to the
handles within your application (so your going to have to reference the
calling form, easy enough), if its in yyour application, then focus back on
the spell check window, otherwise, let it go.

Then on your activate you can perform the same action. Given, there are
probably 100 situations that could exist you need to consider, but maybe
this will give you a starting point.

HTH,
CJ
Ed said:
I changed my code to:

Me.Show()

select case me.dialogresult
Case DialogResult.Cancel
-----right code here

Case DialogResult.Change
-----right code here

Case DialogResult.Ignore
-----right code here

end select

there are no more error messages. The problem now is that the code will
continue executing after Me.Show without waiting for an event on the spell
check form. How can I make it stop after the Me.show? Is it possible? What i
want to happen is somehow mimic the ME.ShowDialog(), but unlike it, i can
switch forms (modeless).
 
Armin
First, here's my objective....If there there is a misspelled word in a textbox on the main form, the spell check form will appear and at the same time, the misspelled word on the main form should be highlighted (I used textbox.select() for this one). By the way, the spell check form is somewhat similar to the spell checker of word

Here comes the problem.... since the spell check form is modal, the highlight for the misspelled word cannot be seen since the focus of the application is on the spell check form. I'm pretty much sure that my code for the highlighting of the misspelled word is working because if i close the spell check form (meaning it loses focus on it and brings the focus back on the main form), i can see that the misspelled word is highlighted

Now just an FYI, this is a complex application handed over to me for maintenance purposes so the whole app is really not my code. What I'm trying to do now is to do as little change to the code as possible (if it can be done, which i hope :p

Cor

Now this is the main reason why I can't just apply the code that you wrote. I know it should be like that too (and as simple as that :)) it's just that the original designer of the code didn't make it that way, he did it a little bit more complex :

CJ
I appreciate the alternative but whoah....i guess i agree with you when you said "extensive" :) Like I said above, I like to do as little change as possible to the code, nevertheless, I will try your suggestion if there are no more easy alternatives :

Jay B. Harlow

As i said above, the original code did not come from me. I was about to try your suggestion but when i saw the code, there is already an eventhandler for each of the button_click events. Aside from the select case Me.dialogresult..... that will process what was clicked on the spell check form, it also has an event handler. Now i have yet to understand how that works but i will work on it :

Thanks again to everyone :) I hope i have cleared some of your questions.....so with those in mind....any more suggestions? :

armi
 
By the way, the part of the code which i am writing myself is onlt the highlighting if the misspelled word. This is the code

---start cod
'ctrl is the textbox contro

startPos = InStr(1, ctrl.Text, strWord
wordLength = Len(strWord
ctrl.Select(startPos - 1, wordLength
ctrl.Focus(
---end cod
 
Hi Ed,

I think you should not be happy with that, I could not understand it,
however now I start to think that someone could have written something as
this.
\\\
Shadows Sub Show()
Dim frm As New Form2
Dim result As DialogResult
result = frm.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Me.Show()
Me.Button1.Parent.Show()
End Sub
///

If this is true you are working on a in my idea, as I call them, by the
maker obfuscated program.

Cor
 
Ed,
It sounds like you seriously need to reconsider what you are attempting!
Consider rewriting the spell check form (from scratch if necessarily), so it
functions in the manner that you require, of course I would question any
spell check form that required ShowDialog anyway.

As has been pointed out only ShowDialog returns the DialogResult. If you
need to use Show, then you need another method to return the DialogResult,
most if not all of these other methods will require your spell form to raise
an event or some sort, otherwise how would the first form know that the
DialogResult was available from the spell check form?

Remember when you design a form, developers rarely design a form to support
both Show & ShowDialog, they design it to use one or the other, at least I
cannot think of a reason why I would design a form to support both. If the
Spell Dialog was designed to return a DialogResult, it sounds like it was
only designed to use ShowDialog, hence your problems.

In other words do it "correctly", any thing else, as Cor puts it, is an
"obfuscated program", a very hard to read & understand program.

Hope this helps
Jay

ed said:
Armin,
First, here's my objective....If there there is a misspelled word in a
textbox on the main form, the spell check form will appear and at the same
time, the misspelled word on the main form should be highlighted (I used
textbox.select() for this one). By the way, the spell check form is somewhat
similar to the spell checker of word.
Here comes the problem.... since the spell check form is modal, the
highlight for the misspelled word cannot be seen since the focus of the
application is on the spell check form. I'm pretty much sure that my code
for the highlighting of the misspelled word is working because if i close
the spell check form (meaning it loses focus on it and brings the focus back
on the main form), i can see that the misspelled word is highlighted.
Now just an FYI, this is a complex application handed over to me for
maintenance purposes so the whole app is really not my code. What I'm trying
to do now is to do as little change to the code as possible (if it can be
done, which i hope :p)
Cor,

Now this is the main reason why I can't just apply the code that you
wrote. I know it should be like that too (and as simple as that :)) it's
just that the original designer of the code didn't make it that way, he did
it a little bit more complex :p
CJ,
I appreciate the alternative but whoah....i guess i agree with you when
you said "extensive" :) Like I said above, I like to do as little change as
possible to the code, nevertheless, I will try your suggestion if there are
no more easy alternatives :)
Jay B. Harlow,

As i said above, the original code did not come from me. I was about to
try your suggestion but when i saw the code, there is already an
eventhandler for each of the button_click events. Aside from the select case
Me.dialogresult..... that will process what was clicked on the spell check
form, it also has an event handler. Now i have yet to understand how that
works but i will work on it :p
Thanks again to everyone :) I hope i have cleared some of your
questions.....so with those in mind....any more suggestions? :)
 
Back
Top