.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to detect spacebar or enter from utility.getstring

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
457 Views, 2 Replies

How to detect spacebar or enter from utility.getstring

vb.net 2008 express
I want to request a string from user and store the response for next request
Then on subsequent requests if spacebar or enter is hit rather than a new
string, use the previous default.
tried the following but doesn't work
when the prompt asks for string, if i hit enter, program ends, instead of
using
preset default value and proceeding to next step
spacebar and enter don't seem to raise the exception, nor do the suceeding
if clauses catch an empty string

'at top of file to store user responses
private m_LasEntry as string

'then in middle of a command sequence:
Dim sEntry As String = ""

Try
If m_LasEntry = "" Then
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something:")
Else
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something :
<" &
m_LasEntry & ">")
End If


Catch ex As Exception

MsgBox("Invalid Input", MsgBoxStyle.Information, "")

End Try

If sEntry = "" Then 'enter key was hit?

'accept default

sEntry = m_LastEntry

Exit Try

ElseIf sEntry = " " Then 'spacebar?

'accept default

sEntry = m_LastEntry

Exit Try

End If

m_LastEntry = sEntry 'save entry for next default

....
any tips appreciated
mark
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

You may be using VB.NET but you're still using COM, so you would probably
get a faster answer in the VB.NET newsgroup, as this has little to do with
.NET or the managed API.

In fact, I can't even remember how that problem was solved, since its been
so long since I've used COM/ActiveX.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"mp" wrote in message
news:6293227@discussion.autodesk.com...
vb.net 2008 express
I want to request a string from user and store the response for next request
Then on subsequent requests if spacebar or enter is hit rather than a new
string, use the previous default.
tried the following but doesn't work
when the prompt asks for string, if i hit enter, program ends, instead of
using
preset default value and proceeding to next step
spacebar and enter don't seem to raise the exception, nor do the suceeding
if clauses catch an empty string

'at top of file to store user responses
private m_LasEntry as string

'then in middle of a command sequence:
Dim sEntry As String = ""

Try
If m_LasEntry = "" Then
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something:")
Else
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something :
<" &
m_LasEntry & ">")
End If


Catch ex As Exception

MsgBox("Invalid Input", MsgBoxStyle.Information, "")

End Try

If sEntry = "" Then 'enter key was hit?

'accept default

sEntry = m_LastEntry

Exit Try

ElseIf sEntry = " " Then 'spacebar?

'accept default

sEntry = m_LastEntry

Exit Try

End If

m_LastEntry = sEntry 'save entry for next default

....
any tips appreciated
mark
Message 3 of 3
Anonymous
in reply to: Anonymous

Hi Tony,
Thanks for the response.
As I'm rewriting a previous app I could change to managed at this point if i
wanted.
Is there a big advantage of one approach over the other in general, or are
some types of projects better in one than the other, or is com just a
temporary bridge til people rewire their brains to net?

if i convert i may just switch it to c# which seems a bit more popular than
vbnet

I did solve the problem just by checking if stringvar.trim.length = 0
why that worked when stringvar = "" or stringvar = " " didn't i don't know.
fwiw
Sub GetStringOrDefault(ByRef InputVariable As String, ByVal PromptString As
String, ByRef DefaultResponse As String)

Try

If DefaultResponse = "" Then

InputVariable = UCase(m_acadDoc.Utility.GetString(0, vbNewLine &
PromptString))

Else

InputVariable = UCase(m_acadDoc.Utility.GetString(0, vbNewLine &
PromptString & "<" & DefaultResponse & ">"))

End If

If InputVariable.Trim.Length = 0 Then

InputVariable = DefaultResponse

Else

DefaultResponse = InputVariable

End If


Catch ex As Exception

MsgBox("Invalid Input", MsgBoxStyle.Information, "")

InputVariable = "user must have cancelled?"

End Try

End Sub

see my response to your other replies if you'd like
thanks again
mark

"Tony Tanzillo" wrote in message
news:6293322@discussion.autodesk.com...
You may be using VB.NET but you're still using COM, so you would probably
get a faster answer in the VB.NET newsgroup, as this has little to do with
.NET or the managed API.

In fact, I can't even remember how that problem was solved, since its been
so long since I've used COM/ActiveX.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"mp" wrote in message
news:6293227@discussion.autodesk.com...
vb.net 2008 express
I want to request a string from user and store the response for next request
Then on subsequent requests if spacebar or enter is hit rather than a new
string, use the previous default.
tried the following but doesn't work
when the prompt asks for string, if i hit enter, program ends, instead of
using
preset default value and proceeding to next step
spacebar and enter don't seem to raise the exception, nor do the suceeding
if clauses catch an empty string

'at top of file to store user responses
private m_LasEntry as string

'then in middle of a command sequence:
Dim sEntry As String = ""

Try
If m_LasEntry = "" Then
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something:")
Else
sEntry = m_acadDoc.Utility.GetString(0, vbNewLine & "Enter something :
<" &
m_LasEntry & ">")
End If


Catch ex As Exception

MsgBox("Invalid Input", MsgBoxStyle.Information, "")

End Try

If sEntry = "" Then 'enter key was hit?

'accept default

sEntry = m_LastEntry

Exit Try

ElseIf sEntry = " " Then 'spacebar?

'accept default

sEntry = m_LastEntry

Exit Try

End If

m_LastEntry = sEntry 'save entry for next default

....
any tips appreciated
mark

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost