Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
IN.............. newbie
Old
  (#1)
Fuddzy
Guest
 
Posts: n/a
Default IN.............. newbie - 06-04-2007, 08:52 AM

Hello

What is the comparable function in Vb6 to the IN function used in databases.
Would it be Switch ??

TIA
Fud

--

.........ooo..................ooo..........

There must be a hundred silver dollars in here. I can't handle that sort
o' money, you've gotta be in the league of lawyers to steal that much.
- J. H. "Flannelfoot" Boggis




   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: IN.............. newbie
Old
  (#2)
Rick Rothstein
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

> What is the comparable function in Vb6 to the IN function used in
databases.
> Would it be Switch ??


Depends... what does the IN function used in databases do?

Rick - MVP


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#3)
Fuddzy
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

Hi Rick

Rick wrote:
<< Depends... what does the IN function used in databases do?>>


IN Operator

Determines whether the value of an expression is equal to any of several
values in a specified list

Syntax

expr [Not] In(value1, value2, . . .)

i.e. where x IN(2, 8, 9)

I know that IN is used to query recordsets and tables............ the neat
thing is that it returns True if x (in this case) is any one of 2, or 8, or
9 (in this case).

I would like to know if VB6 has a similar Function or Operator that could be
used in Procedures/Functions. Its difficult for us newbies to find the
correct function, when we don't know the name of it.

Thanks
Fuddzy

"Rick Rothstein" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED...
> > What is the comparable function in Vb6 to the IN function used in

> databases.
> > Would it be Switch ??

>
> Depends... what does the IN function used in databases do?
>
> Rick - MVP
>
>



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#4)
Bob Butler
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

"Fuddzy" <EMAIL REMOVED> wrote in message news:<3fc3b0f3$EMAIL REMOVED>...
> Hello
>
> What is the comparable function in Vb6 to the IN function used in databases.
> Would it be Switch ??


possibly a select case...

select case thevalue
case "choice1","choice2","choice3":
' code for those 3
case "choice4","choice5":
' code for those 2
case else:
' catch remaining
end select

If you elaborate on what you are trying to do it might help
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#5)
Fuddzy
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

Bob wrote:
<> If you elaborate on what you are trying to do it might help>>

Hi Bob........... here is part of the scenerio

Suppose I want to create a mosaic (similiar to a chessboard) and I would use
a picturebox array of approx 100 controls all built under prg control. While
my loops are building the control array of pictureboxes......... I want to
provide a background color to each.............. thus that part of the code
(If there was such an "IN" operator or function in VB6) would look something
like,.........

If someRow% IN(2,6,9,12) and someIndex% IN(9, 17, 25, 34) then
myPicturebox(someIndex).BackColor = someColor
else
myPicturebox(someIndex).BackColor = someOtherColor
end if

I know I could use a Case Select, but that would take more code than ( the
IN opereator as used in databases)...... so my question still remains as:
What Function or Operator does VB provide for a similar result ??

Thanks
Fud

"Bob Butler" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED m...
> "Fuddzy" <EMAIL REMOVED> wrote in message

news:<3fc3b0f3$EMAIL REMOVED>...
> > Hello
> >
> > What is the comparable function in Vb6 to the IN function used in

databases.
> > Would it be Switch ??

>
> possibly a select case...
>
> select case thevalue
> case "choice1","choice2","choice3":
> ' code for those 3
> case "choice4","choice5":
> ' code for those 2
> case else:
> ' catch remaining
> end select
>
> If you elaborate on what you are trying to do it might help



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#6)
Larry Serflaten
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

"Fuddzy" <EMAIL REMOVED> wrote
>
> Hi Bob........... here is part of the scenerio
>
> Suppose I want to create a mosaic (similiar to a chessboard) and I would use
> a picturebox array of approx 100 controls all built under prg control. While
> my loops are building the control array of pictureboxes......... I want to
> provide a background color to each.............. thus that part of the code
> (If there was such an "IN" operator or function in VB6) would look something
> like,.........
>
> If someRow% IN(2,6,9,12) and someIndex% IN(9, 17, 25, 34) then
> myPicturebox(someIndex).BackColor = someColor
> else
> myPicturebox(someIndex).BackColor = someOtherColor
> end if
>
> I know I could use a Case Select, but that would take more code than ( the
> IN opereator as used in databases)...... so my question still remains as:
> What Function or Operator does VB provide for a similar result ??


You could also say the IN method would take more code than having
the mosiac pre-drawn. The amount of code you use (within reason) should
not be a limiting factor. You should be looking toward lower resources, and
faster response time when deciding on what to use.

To lower resources you should try to use the components that just meet your
requirements. Do you really need a picturebox in all those locations, or would
an image control do? For an example, add an Image control to a new form,
and set its Index property to 0. Then add a picturebox control and paste
in the code below. Note that the checkerboard pattern is supplied using the
logic provided to position the controls. Also note how easy it is to know
which image the user clicked on (as shown in the form's Caption).

HTH
LFS


Private Sub Form_Load()
Dim X As Long, Y As Long, Z As Long

With Picture1
.ScaleMode = vbPixels
.AutoRedraw = True
.AutoSize = True
Set .Picture = Me.Icon
.Visible = False
End With


For Y = 0 To 7
For X = 0 To 7

Z = Y * 8 + X
Picture1.Cls
Picture1.BackColor = Array(vbBlack, vbWhite)((X + Y) And 1)
Picture1.PSet (5, 12)
Picture1.Print Z

If Z Then Load Image1(Z)

With Image1(Z)
.Move X * Picture1.Width, Y * Picture1.Height
.Picture = Picture1.Image
.Visible = True
End With

Next X, Y

End Sub

Private Sub Image1_Click(Index As Integer)
Caption = Index
End Sub










-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#7)
Randy Birch
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:52 AM

Here ... add Picture1 to a form. Inside that, place another picture box and
name it pixboard, and set its index to 0 to create a control array. Add
Command1 and run.

Option Explicit

Private Type ControlLayoutData
totalRows As Long
totalColumns As Long
rowPadding As Long
colPadding As Long
ctlHeight As Long
ctlWidth As Long
platemapTop As Integer
platemapLeft As Integer
boardcolor1 As Long
boardcolor2 As Long
boardbackcolor As Long
End Type

Private Sub Command1_Click()

Dim cld As ControlLayoutData

With cld

.colPadding = 0
.rowPadding = 0
.ctlHeight = 915
.ctlWidth = 915
.platemapTop = 400
.platemapLeft = 400

.totalRows = 8
.totalColumns = 8

.boardbackcolor = &H363559
.boardcolor1 = &HB6A029
.boardcolor2 = &HF3FFE8

End With

Picture1.Visible = False

Call CreateBoard(cld, False)

Picture1.Visible = True

End Sub

Private Sub CreateBoard(cld As ControlLayoutData, _
InvertBoard As Boolean)

Dim cnt As Long
Dim nCol As Long
Dim nRow As Long
Dim pixTop As Long
Dim pixLeft As Long

pixTop = Picture1.Top
pixLeft = Picture1.Left
Picture1.BackColor = cld.boardbackcolor

'Preload all the required controls.
'VB's default state is hidden. Since
'controls are cloned, set the
'initial control's height and width,
'avoiding the need to set it in the
'loop below.
With pixboard(0)
.Height = cld.ctlHeight
.Width = cld.ctlWidth
.BorderStyle = 0
End With


'load the bunch
For cnt = 1 To (cld.totalRows * cld.totalColumns)

Load pixboard(cnt)

Next

cnt = 0

'now position the controls to form
'a grid sized as specified
For nRow = 1 To cld.totalRows
For nCol = 1 To cld.totalColumns

'position and show each
'square
With pixboard(cnt)

.Top = cld.platemapTop + _
((cld.ctlHeight * nRow) - cld.ctlHeight) + _
(cld.rowPadding * (nRow - 1))

.Left = cld.platemapLeft + _
((cld.ctlWidth * nCol) - cld.ctlWidth) + _
(cld.colPadding * (nCol - 1))

'switch colours every second
'square. When abs(invertboard)
'equals 0, Black is at the top.
'when it equals 1, Black is at
'the bottom
If ((nRow + nCol) Mod 2 = Abs(InvertBoard)) Then
.BackColor = cld.boardcolor1
Else
.BackColor = cld.boardcolor2
End If

.Visible = True

End With

cnt = cnt + 1

Next nCol

Next

'size the main picture to reveal
'all the controls
With Picture1

.Width = (cld.ctlWidth * cld.totalColumns) + _
(cld.colPadding * (cld.totalColumns - 1)) + _
((cld.platemapLeft) * 2)

.Height = (cld.ctlHeight * cld.totalRows) + _
(cld.rowPadding * (cld.totalRows - 1)) + _
((cld.platemapTop) * 2)

End With

'resize the form to accomodate the pixbox
'with a bit of margin
With Form1
.Move .Left, .Top, _
Picture1.Width + Picture1.Left + 400, _
Picture1.Height + 800 + Picture1.Top
End With

End Sub



--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


"Fuddzy" <EMAIL REMOVED> wrote in message
news:3fc7cf7a$EMAIL REMOVED...
: Bob wrote:
: <> If you elaborate on what you are trying to do it might help>>
:
: Hi Bob........... here is part of the scenerio
:
: Suppose I want to create a mosaic (similiar to a chessboard) and I would
use
: a picturebox array of approx 100 controls all built under prg control.
While
: my loops are building the control array of pictureboxes......... I want to
: provide a background color to each.............. thus that part of the
code
: (If there was such an "IN" operator or function in VB6) would look
something
: like,.........
:
: If someRow% IN(2,6,9,12) and someIndex% IN(9, 17, 25, 34) then
: myPicturebox(someIndex).BackColor = someColor
: else
: myPicturebox(someIndex).BackColor = someOtherColor
: end if
:
: I know I could use a Case Select, but that would take more code than ( the
: IN opereator as used in databases)...... so my question still remains as:
: What Function or Operator does VB provide for a similar result ??
:
: Thanks
: Fud
:
: "Bob Butler" <EMAIL REMOVED> wrote in message
: news:EMAIL REMOVED m...
: > "Fuddzy" <EMAIL REMOVED> wrote in message
: news:<3fc3b0f3$EMAIL REMOVED>...
: > > Hello
: > >
: > > What is the comparable function in Vb6 to the IN function used in
: databases.
: > > Would it be Switch ??
: >
: > possibly a select case...
: >
: > select case thevalue
: > case "choice1","choice2","choice3":
: > ' code for those 3
: > case "choice4","choice5":
: > ' code for those 2
: > case else:
: > ' catch remaining
: > end select
: >
: > If you elaborate on what you are trying to do it might help
:
:


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#8)
Fuddzy
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:53 AM

Hello

You all provided some cool code as to how I should/could accomplish a coding
goal

However.............. somehow the purpose of my original question (if there
is a comparable VB function that does the same as the IN Operator in
databases) has been missed..

******************
i.e. where x IN(2, 8, 9)

I know that IN is used to query recordsets and tables............ the neat
thing is that it returns True if x (in this case) is any one of 2, or 8, or
9 (in this case).

I would like to know if VB6 has a similar Function or Operator that could be
used in Procedures/Functions. Its difficult for us newbies to find the
correct function, when we don't know the name of it.

*********************
Thanks
Fuddzy


"Fuddzy" <EMAIL REMOVED> wrote in message
news:3fc3b0f3$EMAIL REMOVED...
> Hello
>
> What is the comparable function in Vb6 to the IN function used in

databases.
> Would it be Switch ??
>
> TIA
> Fud
>
> --
>
> ........ooo..................ooo..........
>
> There must be a hundred silver dollars in here. I can't handle that sort
> o' money, you've gotta be in the league of lawyers to steal that much.
> - J. H. "Flannelfoot" Boggis
>
>
>
>



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#9)
Larry Serflaten
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:53 AM


"Fuddzy" wrote
>
> However.............. somehow the purpose of my original question (if there
> is a comparable VB function that does the same as the IN Operator in
> databases) has been missed..


Or you were unable to 'read between the lines'....

> I would like to know if VB6 has a similar Function or Operator that could be
> used in Procedures/Functions.


No there isn't. If there were, you would have been told what it was.
The closest you'll get is the Select/Case method.

LFS





-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: IN.............. newbie
Old
  (#10)
Rick Rothstein
Guest
 
Posts: n/a
Default Re: IN.............. newbie - 06-04-2007, 08:53 AM

> > However.............. somehow the purpose of my original question (if
there
> > is a comparable VB function that does the same as the IN Operator in
> > databases) has been missed..

>
> Or you were unable to 'read between the lines'....
>
> > I would like to know if VB6 has a similar Function or Operator that

could be
> > used in Procedures/Functions.

>
> No there isn't. If there were, you would have been told what it was.
> The closest you'll get is the Select/Case method.


Well, maybe this (longish) one-liner also <g>...

ItemList = "2, 8, 9"
X = 8
Print CBool(UBound(Split(" " & ItemList & _
",", " " & CStr(X) & ",")))

This could be cast into a function like so...

Function InList(ValueToCheck As Variant, _
ParamArray Items() As Variant) As Boolean
InList = CBool(UBound(Split(" " & Join(Items, " ,") & _
",", CStr(ValueToCheck))))
End Function

and called like this

Debug.Print InList(Text1.Text, 2, 8, 9)

There are other variations that are possible depending if you want to
specify the list every time or have the function work with a p***ed String
that contains the list; however, I'd probably opt for a loop inside the
function instead of that mess above.<g>

Rick - MVP


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top