mercredi 28 septembre 2016

Repeated JOptionPane pop-up?

so I'm writing a program that gives the number of minutes for every input of x seconds... now the issue is that once I type in the first value, it asks for another value and divides that....and another value...and another...and so on... how can I get it to only give me one value and finish with that one value instead of a never-ending thing?

import javax.swing.JOptionPane;

class TimeCalculator {
public static void main(String[] args) {

double seconds;
String input;

input = JOptionPane.showInputDialog("Enter any number of seconds");

seconds = Double.parseDouble(input);

if (seconds >= 60);
JOptionPane.showInputDialog(null, "There are " + (seconds/60) + " minutes in " + seconds + " seconds.");


if (seconds >= 3600);
JOptionPane.showInputDialog(null, "There are " + (seconds/60) + " minutes in " + seconds + " seconds.");

if (seconds >= 60);
JOptionPane.showInputDialog(null, "There are " + (seconds/86400) + " minutes in " + seconds + " seconds.");

System.exit(0);




}
}

IF ELSE in Microsoft sql

I have the following column in Microsoft SQL Server called Type and I want to create another column called Type 1. Type 1 would be 1 if account starts with letter A, 2 if account starts with D....

I am new with this so could someone please advise?

Type    Type 1  
AD  1  
AV  1  
AC  1  
DE  2  
DR  2  
DG  2  
KL  3  
KL  3  

If and Set in a Batch file

I have a little problem : I try to put a choice to delete all the text files in the folder, but it's a bit hard. Here's my code :

@echo off 
if not exist *.txt (
echo Il n'y a pas de fichiers txt
) else (
dir /b *.txt
:start
echo voulez vous supprimer ces fichiers textes?
set input=
set /p input=Choice:
if %input%==y goto 1
if %input%==n goto 2
@REM Veuillez appuyer sur "y" ou "n".
@echo Le programme recommence.
goto start

1:
echo Fichiers supprimés 
2: 
echo Fichiers non supprimés
)

I tried with choice, but I can do more things with set.
Thanks for any answer, and also excuse me for bad english.
P.S: The sentences in 1 and 2 means Files deleted/Undeleted files

Tableau If Statement

Here is Tableau DataViz (tab "Other Regions")

I am trying to create columns that

(1) explicitly list region

(2) remaining regions come under "Other Regions"

Value for "Other_Region"

If NOT Region="Ontario" or Region="Prarie" or Region="Quebec" or Region="Yukon" Then "Other Regions" Else Region end

Output is not what I expected. It only lists

(1) Ontario

(2) Other Regions

I was also expecting

  • Prarie
  • Quebec
  • Yukon

My actual data has 200+ regions, hence the need for streamlined statement.

Please guide.

enter image description here

Unity3d ScreenPointToLocalPointInRectangle

I'm having some troubles with the ScreenPointToLocalPointInRectangle() function. This is my code:

void OnTouch(Vector2 position) {
    Vector2 pos;
    if (RectTransformUtility.ScreenPointToLocalPointInRectangle (bgImage.rectTransform, position, Camera.main, out pos)) {
        pos.x = (pos.x / bgImage.rectTransform.sizeDelta.x);
        pos.y = (pos.y / bgImage.rectTransform.sizeDelta.y);
    }

It's not doing anything, the instructions inside the 'if' are not executed. I used Debug.Log() to check the position variable and it's fine.

How can I fix this?

How to get second match from string on Visual Basic?

I'm doing Hangman Game in Visual Basic. I'm looking for typing a letter in a TextBox and clicking a button to check out. If that letter is in String, it will return position but when the word has two matches... How could I do it?

Next code only return the first match, I mean, only position of the first "A".

Dim palabra As String = "PALABRA"

Private Sub BtnComprobar_Click(sender As Object, e As EventArgs) Handles BtnComprobar.Click
    If txtComprobar IsNot "" Then
        Dim letra As String = UCase(txtComprobar.Text)

        If palabra.IndexOf(letra) > -1 Then
            Select Case palabra.IndexOf(letra)
                Case 0
                    Lbl1.Text = letra
                    LblP.ForeColor = Color.Red
                Case 1
                    Lbl2.Text = letra
                    LblA.ForeColor = Color.Red
                Case 2
                    Lbl3.Text = letra
                    LblL.ForeColor = Color.Red
                Case 4
                    Lbl4.Text = letra
                Case 5
                    Lbl5.Text = letra
                    LblB.ForeColor = Color.Red
            End Select
        Else
            errores += 1
            txtErrores.Text = CStr(errores)
        End If
        txtComprobar.Text = ""
    End If
End Sub

Thank for your help

input and output of cmd command

I have next script test.bat:

@ECHO OFF

echo output inVal = %inVal%
SET /p inVal="input "
echo output inVal = %inVal%

dir  >NUL 2>&1
if %errorlevel% == 1 (
    echo non existing dir
) else (
    echo existing dir
    SET /p inVal="input "
    echo output inVal = %inVal%
)

And the output after my inputs is:

> test.bat
output inVal = 5
input 7
output inVal = 7
existing dir
input 3
output inVal = 7
>
> test.bat
output inVal = 3
input 8
output inVal = 8
existing dir
input 2
output inVal = 8
>

first question: on the second run, the output starts with number 3, that should be the last output from the first run, but for some reason it is not. Why?

second question: in second run, the last output should be 2, instead, it is 8: "output inVal = 8" Why?