I've designed Calculator Program, used by String function
Hello Everyone,
I've designed Calculator Program, used by String function. U've any Feedback in this program, cantact me.
Thanks & Regards,
SABARI SARAVANAN M
Certified LabVIEW Associate Developer
Attachments:
calculator.vi 71 KB
Hi Jitendra,
Does the dump log shows that the cause is memory shortage?
Thanks and Best Regards,
Vikas Bittera.
**Points for useful answers**
Similar Messages
-
Design dialog program using the MVC pattern
Hi,
I have to design a dialog program using the MVC pattern , with all the controllers lying inside function modules.
I have searched out on net and could find out that BSP applications are designed using the MVC concept.Please suggest how can the dialog program be designed using MVC pattern.I'm currently developing a classic Dynpro dialog program. I have a module pool, with screens. I've tightly coupled the module pool with a controller class. Anything that happens in the module pool, is handled by the controller class. All the logic of screen handling is done by the controller class.
What remains in the module pool is the capturing of the okcode. the next screen to go to (if applicable), the setting of field attributes. But the okcode is sent straight to the controller for processing, and the screen/field information is also held in the controller.
I've also rewritten the auto-generated tab handling code, so the logic is done via a class.
So, it is possible - just aim to have as LITTLE as possible in the module pool or function group.
The model, of course, is in a separate class. -
How to use SQL String functions with JPA and SAP NW
Hi Everyone,
I'm recently got the following problem:
I have a Web Service project using JPA. But as i found out SAPs JPA implementation or more precisely openSQL restricts the use of the LOWER() function, which converts a String to lower case.
Now I am looking for some sort of workaround. I want to execute the following JPQL query:
SELECT bp FROM BusinessPartner bp WHERE LOWER(bp.companyName) LIKE LOWER(:companyName)
I assume there is somewhere a flag to disable this restrictions, because there might be cases, like mine, where this standard functions are needed.
Kind Regards,
CarlHi Vladimir,
no it's not the same issue, because I am asking for a solution for this problem. There have to be ways to bypass this. Otherwise you can't use JPA properly. This is too much of a restriction!
Is there no possibility to change to another implementation than openSQL?
Regards,
Carl
Edited by: Carl Simon Heckmann on Feb 2, 2009 2:26 PM -
Using php string function on update and/or insert
So, for instance, I want to place a month/day in a column but I want the insert or update to strip out any forward-slash character that might be submitted.
How do I get str_replace() to be applied on insert or update to prevent the insertion of a forward-slash.
I am having trouble figuring out to what I should apply function. There's nothing in the form's value field and even if I echo in a variable or something like this:
echo $row_rssubscription_payment_copy['expirationDate'];
I have trouble "seeing" what the syntax should be. My guesses are all wrong.
Will someone please lend a hand.
Thanks very much!Hi alterity,
if you´d use ADDT´s datepicker, you wouldn´t need to worry about that :-)
honestly, if a column like "expirationDate" is supposed to store the year-month-day value in a mysql compatible format, I can´t think of any reason to not use the datepicker.
However it´s possible to apply stuff like that to a certain transaction value before it´s getting submitted to a table -- here´s a str_replace example which would replace a forward slash (/) with a hyphen:
$tNG->setColumnValue("columnname_here", str_replace('/','-',$tNG->getColumnValue("columnname_here")));
All you´d need to do, is to embed such things in a Custom Trigger and make sure it´s defined as BEFORE trigger.
Cheers,
Günter Schenk
Adobe Community Expert, Dreamweaver -
String function to count total number of a specific character.
Gurus,
I've been trying to use INSTR to decipher a string to count the number of pipes in each string. Anyone have a simple SQL which shows how to use a string function to return a count of a specific character?
Thanks
-ScottHi, Scott,
To see how many '|' characters are in txt, you can see how much txt shrinks when you remove the '|'s.
LENGTH (txt) - NVL ( LENGTH ( TRANSLATE ( txt
, 'x|'
, 'x'
, 0
)The expression above works in any version of Oracle.
Starting in Oracle 11, you can also use REGEXP_COUNT:
REGEXP_COUNT (txt, '\|')'|' is a special symbol in regular expressions, so it has to be "escaped" ('\|') to indicate the pipe character. -
Simple calculator to use log, successor, predecessor ?
Hello. I have this simple calculator program, and I am having trouble with the log, successor (if 8 entered returns 9), predecessor (if 8 entered returns 7). The log gets this error:
Calculator.java:113: log(double) in java.lang.Math cannot be applied to (int,int)
result = (int)Math.log(result, stringToInteger(ioField.getText()));
I did the same thing with power, and it seems to work so I'm a little confused about that.
If anyone can help me out it would be greatly appreciated, and thanks in advance!
Here's the code (commented out code is what I need help with):
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator extends JFrame implements ActionListener
public static final int WIDTH = 400;
public static final int HEIGHT = 200;
public static final int NUMBER_OF_DIGITS = 30;
private JTextField ioField;
private int result = 0;
public Calculator()
setSize(WIDTH, HEIGHT);
setTitle("GUI Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel textPanel = new JPanel();
textPanel.setLayout(new FlowLayout());
ioField = new JTextField("Enter numbers here.", NUMBER_OF_DIGITS);
ioField.setBackground(Color.WHITE);
textPanel.add(ioField);
add(textPanel, BorderLayout.NORTH);
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.BLUE);
buttonPanel.setLayout(new GridLayout(5, 2));
JButton addButton = new JButton("+");
addButton.addActionListener(this);
buttonPanel.add(addButton);
JButton subButton = new JButton("-");
subButton.addActionListener(this);
buttonPanel.add(subButton);
JButton multButton = new JButton("*");
multButton.addActionListener(this);
buttonPanel.add(multButton);
JButton divButton = new JButton("/");
divButton.addActionListener(this);
buttonPanel.add(divButton);
JButton expButton = new JButton("^");
expButton.addActionListener(this);
buttonPanel.add(expButton);
JButton logButton = new JButton("v");
logButton.addActionListener(this);
buttonPanel.add(logButton);
JButton sucButton = new JButton("s");
sucButton.addActionListener(this);
buttonPanel.add(sucButton);
JButton preButton = new JButton("p");
preButton.addActionListener(this);
buttonPanel.add(preButton);
JButton clearButton = new JButton("C");
clearButton.addActionListener(this);
buttonPanel.add(clearButton);
add(buttonPanel, BorderLayout.CENTER);
public void actionPerformed(ActionEvent e)
try
assumingCorrectNumberFormats(e);
catch(NumberFormatException e2)
ioField.setText("Error - Reenter number.");
public void assumingCorrectNumberFormats(ActionEvent e)
String actionCommand = e.getActionCommand();
if(actionCommand.equals("+"))
result = result + stringToInteger(ioField.getText());
ioField.setText(Integer.toString(result));
else if(actionCommand.equals("-"))
result = result - stringToInteger(ioField.getText());
ioField.setText(Integer.toString(result));
else if(actionCommand.equals("*"))
result = result * stringToInteger(ioField.getText());
ioField.setText(Integer.toString(result));
else if(actionCommand.equals("/"))
result = result / stringToInteger(ioField.getText());
ioField.setText(Integer.toString(result));
else if(actionCommand.equals("^"))
result = (int)Math.pow(result, stringToInteger(ioField.getText()));
ioField.setText(Integer.toString(result));
/* else if(actionCommand.equals("v"))
result = (int)Math.log(result, stringToInteger(ioField.getText()));
ioField.setText(Integer.toString(result));
else if(actionCommand.equals("s"))
result = result + 1;
else if(actionCommand.equals("p"))
result = result - 1;
*/ else if(actionCommand.equals("C"))
result = 0;
ioField.setText("0");
else
ioField.setText("Unexpected error.");
public static int stringToInteger(String stringObject)
return Integer.parseInt(stringObject.trim());
public static void main(String[] args)
Calculator gui = new Calculator();
gui.setVisible(true);
}A 'double' is not the same as an 'int' and they can't fit the one value-type into the memory of the other.
Although this is a logical math problem, simple for us, we have better memory than a computer.
An integer maps a certain amount of memory to fix its maximum value, when you cast, you must cast into a type that is the same or smaller in terms of memory byte size.
Just like you can't cast some objects as others, you can't cast a double as an int.
The error is telling you that the result of a method call is incompatiable with the argument of another method call.
The fault lies at Calculator.java source file at line 113 in the file. This is where you call the method log() which requires an argument of type 'double' which is located in Math class log method where the two arguments are 'int' and 'int'.
However, in your call, you inflect the reference 'result' as the product of the method call in which the 1st argument is also 'result'
That in itself is bad design. It's like saying "Joe is the product of Mike (who uses Joe)."
Memory-wise, this could cause possible leaks. -
Introduction
In SQL Server Analysis Services (SSAS), you can create a calculated measure in SQL Server Data Tool (SSDT)/Boniness Integrated Development Studio (BIDS). Sometimes you may need to create calculated measure by using AMO in a C# or VB project.
In this article, I will demonstrate so how to create calculated measure using AMO in SSAS?
Prerequisites
Before create calculated measure using AMO, you need to ensure that the following components were installed in your server.
The multidimensional database AdventureWorks Multidimensional Model 2012
A SQL Server with SSIS and SSAS installed
The AMO libraries installed:
X86 Package (SQL_AS_AMO.msi)
X64 Package (SQL_AS_AMO.msi)
Solution
Here is the detail steps to create calculated measure using AMO in SSAS.
Open SSDT and create a new SSIS project.
Drag Script Task to the design surface.
Click SSIS-> Variables to open the Variables window and add two variables that used to connect to the server and database.
Create a connection to connect to SSAS server.
Rename the connection name to ssas.
Double click the Script Task to open Script Task Editor.
Add Connection and Database variables to ReadWriteVariables textbox and then click Edit Script button.
Add AMO reference in the Solution Explore window.
Copy the script below and paste it into the script.
Dim objServer As Server
Dim objDatabase As Database
Dim strDataBaseID As String
Dim objCube As Cube
Dim objMdxScript As MdxScript
Dim objCommand As Command
Dim strCommand As String
objServer = New Server
objServer.Connect("localhost")
objDatabase = objServer.Databases("AdventureWorksDW2012Multidimensional-EE2")
strDataBaseID = objDatabase.ID
If objDatabase.Cubes.Count > 0 Then
objCube = objDatabase.Cubes("Adventure Works")
If objCube.MdxScripts.Count > 0 Then
objMdxScript = objCube.MdxScripts("MdxScript")
objMdxScript = objCube.MdxScripts(0)
Else
objCube.MdxScripts.Add("MdxScript", "MdxScript")
objMdxScript = objCube.MdxScripts("MdxScript")
End If
objCommand = New Command
strCommand = "CREATE MEMBER CURRENTCUBE.[Measures].[Multipy Measures By 3]"
strCommand = strCommand & " AS [Measures].[Internet Sales Amount] * 3, "
strCommand = strCommand & " VISIBLE = 1 ; "
objCommand.Text = strCommand
objMdxScript.Commands.Add(objCommand)
objMdxScript.Update()
objCube.Update()
End If
objServer.Disconnect()
Then you can run this SSIS package to create the calculated measure.
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thanks,
Is this a supported scenario, or does it use unsupported features?
For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
in a supported way?
Thanks! Josh -
ForLoop Square Root Calculator Program
* Programmer: R McBride
* Date: November 29, 2006
* Filename: SquareRootForLoop.java
* Purpose: This program uses for()loops to
* find the square root of a number
* up to four decimal places long.
import APCS.Keyboard;
class SquareRootForLoopTest1
public static void main (String[]args)
//define variables
double SquareRoot = 0; //holds initial value
double num1 = 0;
boolean done = false;
double tempReg1 = 0; //holds initial value of i
double tempReg2 = 0; //holds
double tempReg3 = 0;
//while loop start
// while (!done)
//program input
System.out.println("\t\t\tSQUARE ROOT CALCULATOR PROGRAM");
System.out.println(""); //skip line
System.out.println("Enter the number you would like to be square rooted or [0] to end the program.");
System.out.print("");
SquareRoot = Keyboard.readInt();
System.out.println(""); //skip line
System.out.println("You entered "+SquareRoot+".");
System.out.println(""); //skip line
//for loop function
for(int i = 0; i < 999999; i++)
tempReg1 = i * i;
tempReg2 = i;
// while (!done)
if(tempReg1 == SquareRoot)
System.out.println("The square root is "+tempReg2);
System.out.println("");
else
System.out.print("");
//while loop check to finish
// if(SquareRoot == 0)
// done = true;
// }//end while loop
}Here is my code for and of you who ever wants to use it. Our assignment was to make a square root calculator using ForLoop (a.k.a. no square root functions).
My question is, how would I make it increase by .0001 instead of 1 every loop? I need it to do that so I can find square roots of numbers of numbers that have decimals for squares.* Programmer: R McBride
* Date: November 29, 2006
* Filename: SquareRootForLoop.java
* Purpose: This program uses for()loops to
* find the square root of a number
* up to four decimal places long.
import APCS.Keyboard;
class SquareRootForLoopTest1
public static void main (String[]args)
//define variables
double SquareRoot = 0; //holds initial value
double num1 = 0;
boolean done = false;
double tempReg1 = 0; //holds initial value of i
double tempReg2 = 0; //holds
double tempReg3 = 0;
//while loop start
// while (!done)
//program input
System.out.println("\t\t\tSQUARE ROOT CALCULATOR PROGRAM");
System.out.println(""); //skip line
System.out.println("Enter the number you would like to be square rooted or [0] to end the program.");
System.out.print("");
SquareRoot = Keyboard.readInt();
System.out.println(""); //skip line
System.out.println("You entered "+SquareRoot+".");
System.out.println(""); //skip line
//for loop function
for(double i = 0; i < 999999; i+=.0001)
tempReg1 = i * i;
tempReg2 = i;
// while (!done)
if(tempReg1 == SquareRoot)
System.out.println("The square root is "+tempReg2);
System.out.println("");
else
System.out.print("");
//while loop check to finish
// if(SquareRoot == 0)
// done = true;
// }//end while loop
}Still doesn't work. =[ -
Could u guys help me with a calculator program
hi
i'm writing a calculator program for my java class and the code ur about to read actually works but when i click on the keypad i don't get any numbers in the display screen, the textfield
Could u guys have a look at it please:
here we go
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
public class Calculator extends JFrame implements ActionListener {
public boolean firstDigit;
public int temp1 = 0;
public int temp = 0;
public int result = 0;
public String opr = "";
JTextField tf= new JTextField ("",20) ; //sets the display initially at 0
//tf.setEditable (false) ; this doesn't work
JPanel pan = new JPanel() ;
JButton bclear= new JButton("C") ;
JButton b0= new JButton("0") ;
JButton badd = new JButton("+") ;
JButton bsub = new JButton("-") ;
JButton bmult = new JButton("x");
JButton bdiv = new JButton("/") ;
JButton bpoint= new JButton(".");
JButton bequal = new JButton("=");
public Calculator (String title) // constructor
super(title) ;
pan.add(tf);
for ( int i=1; i<=3; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt); }
badd.addActionListener(this);
pan.add(badd);
for ( int i=4; i<=6; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bsub.addActionListener(this);
pan.add(bsub);
for ( int i=7; i<=9; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bmult.addActionListener(this);
pan.add(bmult);
bclear.addActionListener(this);
pan.add(bclear);
b0.addActionListener(this);
pan.add(b0);
bpoint.addActionListener(this);
pan.add(bpoint);
bequal.addActionListener(this);
pan.add(bequal);
bdiv.addActionListener(this);
pan.add(bdiv);
//pan.add(new Button(""));
setContentPane(pan) ;
public boolean action(Event e, Object o)
//checks for operator keys
if (e.target == badd)
temp1 = temp; //to "save" for calculation
opr = "+";
else if (e.target == bsub)
temp1 = temp;
opr = "-";
else if (e.target == bmult)
temp1 = temp;
opr = "*";
else if (e.target == bdiv)
temp1 = temp;
opr = "/";
else if (e.target == bequal)
result = calculate(temp1,opr,temp);
tf.setText(Integer.toString(result)); //does the calculation
temp= result; //to be able to do an operation on the result
else if (e.target == bclear)
tf.setText("");
temp1 = 0; //resets the temps and display to 0
temp = 0;
else
//numeric buttons
if (firstDigit)
tf.setText( o.toString() );
firstDigit = false;
temp = Integer.parseInt(tf.getText()); //saves the number in a temp
else
tf.setText(tf.getText() + o.toString()); //for numbers longer than 1 digit
temp = Integer.parseInt(tf.getText());
return true;
firstDigit = true; // GET READY FOR NEXT NUMBER
return true;
public int calculate(int num1,String op, int num2 )
// calculate the numbers
int answers = 0;
if (op == "+")
answers = num1 + num2; //does the calculation for +
else if(op == "-")
answers = num1 - num2; //does the calculation for -
else if(op == "/")
if(num2 == 0)
tf.setText("ERROR");//gives error message if dividing by 0
else
answers = num1 / num2;
else if(op == "*")
answers = num1 * num2; //does the calculation for *
return answers;
public void actionPerformed(ActionEvent e) {
Object source = e.getSource() ;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName() );
catch (Exception e) {
System.err.println("impossible to use system setting : " + e ); }
Calculator fen = new Calculator("CALCULATOR");
fen.setSize(235, 300);
fen.setVisible(true);
fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);I Hope this would help you.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=2&txtCodeId=2275
Thanks,
Vikas Karwal
[email protected] -
Move used variables/strings
Dear all,
I try to use Dasylab to control and collect data from several equipments at lab (thermostat, stirrer, syringe pump, manostat, thermometer...). Now I have prepared several worksheets (each for single equipment) and it +- works (it is necessary to complete with some functionality but for collecting current lab data it is sufficient). The worksheets works, but only for single equipment, but I need to work with all of them. So I rebuild the worksheets that the each equipment is packed at black boxes (each worksheet one black box ant it works). Then I save all of black boxes and put them to one worksheet. Unfortunately, the worksheet prepared this way doesn’t work because there are problems with global string and variables. When I save the black box, I don't save the string/variables definitions. For instance the expression of one string in original worksheet is calculated automatically this way: "R" + SubStr( "000",1, 3-(${VAR_51}>=1000)-(${VAR_51}>=100)-(${VAR_51}>10)) + StrFmt(${VAR_51},8,0)+${STR_52} to prepare output string "R0120\r". I am able to export and import global string and variables but only as whole package of 999 variables. I don’t know how to move only used ones (I am able to move them at TXT format, but I am not able to read them to Dasilab as variables).
I have two questions:
1 - Is there any possibility to set "calculate expression automatically" for string/variable during running of program (using some action module or something like that)?
2 - Is there any possibility to save only used strings/variables and collected several packages of variables to one (for instance VAR_1-VAR_50 for thermostat and VAR_100-VAR_150 for thermometer)?I found that if I used the Define Global Variable dialog, and clicked the Save button, it gave me a choice of saving defined variables (those whose settings are not the default) or variable with descriptions.
I saved the file. It gave me a file that included all of the information.
I tried to use the Global Variables and Strings Import dialog, but the file was not ordered correctly.
I opened it in Excel and changed the columns around to match the Help (see picture). Then, I saved it as a TXT file again.
It imported with some errors - notably the additional settings, such as read at start, do not import. The one formula that I created imported correctly.
I think that you can save the used variables from your various worksheets, combine them into one file, change the order of the columns. Since it's a text file, you can change the variable numbers if you need to...
Unfortunately, you cannot import strings this way, as the Help says "DASYLab can only read in strings from VAR formats." Personally, I agree that this is a major limitation!
- cj
Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab. -
Program using class "cl_salv_table"
Hi Experts,
I am new to this class (cl_salv_table). I wrote a program with general ABAP code. But, according to my standard I should use standard ALV factory class i.e., 'CL_SALV_TABLE'. I wouls appreciate if anybody could send me the code using this class. Here is the code which I have written.
REPORT zrgae_acctquery
NO STANDARD PAGE HEADING
LINE-SIZE 190
LINE-COUNT 65
MESSAGE-ID zrga.
Program Title : SAP Account Coding Block Transaction Query Program*
Description : This program loads the legacy General Ledger *
account monthly net activity into the SAP-FI *
system using LSMW. This conversion pertains to *
companyu2019s GL account balances beginning with *
FY07 YE, posting monthly net changes in the *
accounts for FY2008 and FY2009 through go-live. *
Run Frequency: The Z-transaction must be available at any time *
an end user requires the conversion information. *
T A B L E D E C L A R A T I O N
TABLES: ztt_rga_xreft.
D A T A D E C L A R A T I O N
DATA: group_id(3) TYPE c,
l_line TYPE i.
I N T E R N A L T A B L E S
TYPES: BEGIN OF lty_ztt_rga_xreft,
ctacct TYPE ztt_rga_xreft-ctacct,
ctrc01 TYPE ztt_rga_xreft-ctrc01,
ctrc02 TYPE ztt_rga_xreft-ctrc02,
ctrc03 TYPE ztt_rga_xreft-ctrc03,
ctrc04 TYPE ztt_rga_xreft-ctrc04,
ctrc05 TYPE ztt_rga_xreft-ctrc05,
ctrc06 TYPE ztt_rga_xreft-ctrc06,
ctrc07 TYPE ztt_rga_xreft-ctrc07,
ctrc08 TYPE ztt_rga_xreft-ctrc08,
bukrs TYPE ztt_rga_xreft-bukrs,
prctr TYPE ztt_rga_xreft-prctr,
kostl TYPE ztt_rga_xreft-kostl,
saknr TYPE ztt_rga_xreft-saknr,
aufnr TYPE ztt_rga_xreft-aufnr,
sap_offset TYPE ztt_rga_xreft-sap_offset,
END OF lty_ztt_rga_xreft.
DATA: lt_data TYPE STANDARD TABLE OF lty_ztt_rga_xreft, lwa_data TYPE lty_ztt_rga_xreft.
S E L E C T I O N S C R E E N D E F I N I T I O N S *
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
PARAMETERS: p_lgsap RADIOBUTTON GROUP b1 USER-COMMAND rad DEFAULT 'X',
p_saplg RADIOBUTTON GROUP b1.
SELECTION-SCREEN END OF BLOCK a1.
SKIP.
SELECTION-SCREEN BEGIN OF BLOCK a2 WITH FRAME TITLE text-002. "ACC
SELECT-OPTIONS: s_lccode FOR ztt_rga_xreft-ctrc01 MODIF ID acc,
s_ldiv FOR ztt_rga_xreft-ctrc02 MODIF ID acc,
s_lreg FOR ztt_rga_xreft-ctrc03 MODIF ID acc,
s_lloc FOR ztt_rga_xreft-ctrc04 MODIF ID acc,
s_lcctr FOR ztt_rga_xreft-ctrc05 MODIF ID acc,
s_lacct FOR ztt_rga_xreft-ctrc06 MODIF ID acc,
s_lsacct FOR ztt_rga_xreft-ctrc07 MODIF ID acc.
SELECTION-SCREEN END OF BLOCK a2.
SKIP.
SELECTION-SCREEN BEGIN OF BLOCK a3 WITH FRAME TITLE text-003. "ALL
SELECT-OPTIONS: s_bukrs FOR ztt_rga_xreft-bukrs MODIF ID all,
s_prctr FOR ztt_rga_xreft-prctr MODIF ID all,
s_kostl FOR ztt_rga_xreft-kostl MODIF ID all,
s_saknr FOR ztt_rga_xreft-saknr MODIF ID all,
s_aufnr FOR ztt_rga_xreft-aufnr MODIF ID all.
SELECTION-SCREEN END OF BLOCK a3.
A T S E L E C T I O N S C R E E N
AT SELECTION-SCREEN OUTPUT.
CASE 'X'.
WHEN p_saplg.
group_id = 'ACC'.
SET CURSOR FIELD 'S_BUKRS-LOW'.
WHEN p_lgsap.
group_id = 'ALL'.
SET CURSOR FIELD 'S_LCCTR-LOW'.
ENDCASE.
LOOP AT SCREEN.
IF screen-group1 = group_id.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
S T A R T O F S E L E C T I O N
START-OF-SELECTION.
CLEAR l_line.
IF p_lgsap = 'X'. " If legacy input filled
INFINIUM CASE-I VALIDATIONS & OUTPUT *
PASSING INFINIUM 'COST CENTER','ACCOUNT',& 'SUB ACCT' *
IF s_lcctr-low NE ' ' AND s_lacct-low NE ' ' AND s_lsacct-low NE ' '.
SELECT ctrc01
ctrc02
ctrc03
ctrc04
ctrc05
ctrc06
ctrc07
ctrc08
bukrs
prctr
kostl
saknr
aufnr
sap_offset
FROM ztt_rga_xreft INTO TABLE lt_data
WHERE ctrc05 IN s_lcctr
AND ctrc06 IN s_lacct
AND ctrc07 IN s_lsacct.
DESCRIBE TABLE lt_data LINES l_line.
IF l_line < 0.
MESSAGE e001(zrga) with 'Cost Ctr,Acct,SubAcct are not valid.pl check'.
ENDIF.
INFINIUM CASE-II VALIDATIONS & OUTPUT *
PASSING INFINIUM 'COST CENTER'&'ACCOUNT' *
ELSEIF s_lcctr-low NE ' ' AND s_lacct-low NE ' '
AND s_lsacct-low EQ ' '.
SELECT ctrc01
ctrc02
ctrc03
ctrc04
ctrc05
ctrc06
ctrc07
ctrc08
bukrs
prctr
kostl
saknr
aufnr
sap_offset
FROM ztt_rga_xreft INTO TABLE lt_data WHERE ctrc05 IN s_lcctr
AND ctrc06 IN s_lacct.
DESCRIBE TABLE lt_data LINES l_line.
IF l_line < 0.
MESSAGE e002(zrga) with 'Cost Center,Account are not valid...pl check'.
ENDIF.
ENDIF.
INFINIUM CASE-III VALIDATIONS & OUTPUT *
PASSING INFINIUM 'COMPANY CODE'&'ACCOUNT' *
ELSEIF s_lccode-low NE ' ' AND s_lacct-low NE ' '.
SELECT ctrc01
ctrc02
ctrc03
ctrc04
ctrc05
ctrc06
ctrc07
ctrc08
bukrs
prctr
kostl
saknr
aufnr
sap_offset
FROM ztt_rga_xreft INTO TABLE lt_data WHERE ctrc01 IN s_lccode
AND ctrc06 IN s_lacct.
DESCRIBE TABLE lt_data LINES l_line.
IF l_line < 0.
MESSAGE e003(zrga) with 'Company code,Acct are not valid.pl check'.
ENDIF.
ELSE. " If SAP input filled
SAP CASE-I VALIDATIONS & OUTPUT *
PASSING SAP 'COST CENTER','ACCOUNT'&'INTERNAL ORDER' *
IF s_kostl-low NE ' ' AND s_saknr-low NE ' ' AND s_aufnr-low NE ' '.
SELECT ctrc01
ctrc02
ctrc03
ctrc04
ctrc05
ctrc06
ctrc07
ctrc08
bukrs
prctr
kostl
saknr
aufnr
sap_offset
FROM ztt_rga_xreft INTO TABLE lt_data WHERE kostl IN s_kostl
AND saknr IN s_saknr
AND aufnr IN s_aufnr.
DESCRIBE TABLE lt_data LINES l_line.
IF l_line < 0.
MESSAGE e004(zrga) with 'Cost Ctr,Acct,Int order are not valid...pl check'.
ENDIF.
SAP CASE-II VALIDATIONS & OUTPUT *
PASSING SAP 'COST CENTER'&'ACCOUNT' *
ELSEIF s_kostl-low NE ' ' AND s_saknr-low NE ' ' AND s_aufnr-low EQ ' '.
SELECT ctrc01
ctrc02
ctrc03
ctrc04
ctrc05
ctrc06
ctrc07
ctrc08
bukrs
prctr
kostl
saknr
aufnr
sap_offset
FROM ztt_rga_xreft INTO TABLE lt_data WHERE kostl IN s_kostl
AND saknr IN s_saknr.
DESCRIBE TABLE lt_data LINES l_line.
IF l_line < 0.
MESSAGE e005(zrga) with 'Cost Ctr,Acct are not valid...pl check'.
ENDIF.
ENDIF.
ENDIF.
O U T P U T
IF p_lgsap = 'X'. " If legacy input filled
WRITE:/2 'Infinium Company', 40 s_lccode-low,
/2 'Infinium Division', 40 s_ldiv-low,
/2 'Infinium Region', 40 s_lreg-low,
/2 'Infinium Location', 40 s_lloc-low,
/2 'Infinium Cost center', 40 s_lcctr-low,
/2 'Infinium Account', 40 s_lacct-low,
/2 'Infinium Sub-account', 40 s_lsacct-low.
ELSE. "If SAP input filled
WRITE:/2 'SAP Company', 40 s_bukrs-low,
/2 'SAP Cost center', 40 s_kostl-low,
/2 'SAP Profit center', 40 s_prctr-low,
/2 'SAP Account', 40 s_saknr-low,
/2 'SAP order', 40 s_aufnr-low.
ENDIF.
WRITE:/ sy-uline(190).
FORMAT COLOR COL_HEADING ON.
WRITE:/1 sy-vline,
2 'Infinium Company',
17 sy-vline,
18 'Infinium Division',
37 sy-vline,
38 'Infinium Region',
57 sy-vline,
58 'Infinium Location',
77 sy-vline,
78 'Infinium Cost Center',
97 sy-vline,
98 'Infinium Account',
114 sy-vline,
115 'Infinium Sub Account',
134 sy-vline.
FORMAT COLOR COL_HEADING OFF.
FORMAT COLOR COL_POSITIVE ON.
WRITE: 135 'SAP Company',
144 sy-vline,
145 'SAP Profit Center',
154 sy-vline,
155 'SAP Cost Center',
164 sy-vline,
165 'SAP Account',
174 sy-vline,
175 'SAP Order',
190 sy-vline.
FORMAT COLOR COL_POSITIVE OFF.
WRITE:/1 sy-vline.
WRITE:/ sy-uline(190).
WRITE:/ sy-uline(190).
LOOP AT lt_data into lwa_data.
FORMAT COLOR COL_HEADING ON.
WRITE:/1 sy-vline,
2 lwa_data-ctrc01,
17 sy-vline,
18 lwa_data-ctrc02,
37 sy-vline,
38 lwa_data-ctrc03,
57 sy-vline,
58 lwa_data-ctrc04,
77 sy-vline,
78 lwa_data-ctrc05,
97 sy-vline,
98 lwa_data-ctrc06,
114 sy-vline,
115 lwa_data-ctrc07,
134 sy-vline.
FORMAT COLOR COL_HEADING OFF.
FORMAT COLOR COL_POSITIVE ON.
WRITE: 135 lwa_data-bukrs,
144 sy-vline,
145 lwa_data-prctr,
154 sy-vline,
155 lwa_data-kostl,
164 sy-vline,
165 lwa_data-saknr,
174 sy-vline,
175 lwa_data-aufnr,
190 sy-vline.
FORMAT COLOR COL_POSITIVE OFF.
WRITE:/ sy-uline(190).
append lwa_data to lt_data.
clear lwa_data.
ENDLOOP.HI nani,
welcome
This is a sample program to illustrate several techniques:
use of dynamic selections
persistent data stored into cluster INDX
data definition at runtime
display internal table using SALV class
Just copy the code into a new program, create include for events, then copy status STANDARD from program SAPLSALV.
u have to add the SAVE function code to the disk button. It allow you to save modifications to the database.
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Report zkarthik_update
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
report zkarthik_update.
Data definition
type-pools: rsds.
data: is_x030l type x030l,
it_x031l type table of x031l,
is_x031l type x031l.
data: w_selid type rsdynsel-selid,
it_tables type table of rsdstabs,
is_tables type rsdstabs,
it_fields type table of rsdsfields,
it_expr type rsds_texpr,
it_ranges type rsds_trange,
it_where type rsds_twhere,
is_where type rsds_where,
w_active type i.
data: w_repid type sy-repid,
w_dynnr type sy-dynnr,
wt_dynp type table of dynpread,
ws_dynp type dynpread.
data: it_content type ref to data,
is_content type ref to data.
data: w_okcode type sy-ucomm.
data: w_fdkey type x value u201801u2032.
data: w_akey type indx-srtfd,
w_rkey type indx-srtfd,
w_fkey type indx-srtfd.
Include to handle events on ALV display screen
include zbc_query_events.
field-symbols: <itab> type standard table,
<irec> type any.
Macros
define table_error.
message e398(00) with u2018Tableu2019 p_table &1.
end-of-definition.
define fixed_val.
assign component is_x031l-fieldname of structure <irec> to <fld>.
if sy-subrc = 0.
<fld> = &1.
endif.
end-of-definition.
Selection screen
selection-screen: begin of block b01 with frame.
parameters: p_table type tabname obligatory u201Ctable
memory id dtb
matchcode object dd_dbtb_16.
selection-screen: begin of line,
pushbutton 33(20) selopt user-command sel,
comment 55(15) selcnt,
end of line.
selection-screen: skip.
parameters: p_field type fieldname, u201Cfield
p_value type text132. u201Cvalue
selection-screen: end of block b01,
skip,
begin of block b02 with frame.
parameters: p_displ type c as checkbox default u2018Xu2019, u201Cdisplay
p_systm type c as checkbox. u201Csystem
selection-screen: end of block b02.
Initialization
initialization.
move u2018@4G@ Filter recordsu2019 to selopt.
ws_dynp-fieldname = u2018P_TABLEu2019.
append ws_dynp to wt_dynp.
Get dynamic selection from cluster
w_akey(1) = u2018Au2019.
w_akey+1(12) = sy-uname.
import w_active from database indx(xy) id w_akey.
w_rkey(1) = u2018Ru2019.
w_rkey+1(12) = sy-uname.
import it_expr from database indx(xy) id w_rkey.
w_rkey(1) = u2018Fu2019.
w_rkey+1(12) = sy-uname.
import it_fields from database indx(xy) id w_fkey.
PBO
at selection-screen output.
if w_active is initial.
clear: selcnt.
else.
write w_active to selcnt left-justified.
endif.
PAI
at selection-screen.
if p_table ne is_x030l-tabname.
perform f_init_table.
endif.
if sy-ucomm = u2018SELu2019.
if w_selid is initial.
perform f_init_selections.
endif.
Display free selection dialog
call function u2018FREE_SELECTIONS_DIALOGu2019
exporting
selection_id = w_selid
title = u2018Selectionu2019
status = 1
as_window = u2018Xu2019
importing
expressions = it_expr
field_ranges = it_ranges
number_of_active_fields = w_active
tables
fields_tab = it_fields
exceptions
others = 1.
Write dynamic selection to cluster
w_akey(1) = u2018Au2019.
w_akey+1(12) = sy-uname.
export w_active to database indx(xy) id w_akey.
w_rkey(1) = u2018Ru2019.
w_rkey+1(12) = sy-uname.
export it_expr to database indx(xy) id w_rkey.
w_rkey(1) = u2018Fu2019.
w_rkey+1(12) = sy-uname.
export it_fields to database indx(xy) id w_fkey.
endif.
if p_field is not initial.
read table it_x031l into is_x031l
with key fieldname = p_field.
if sy-subrc = 0.
if is_x031l-flag1 o w_fdkey.
message e129(53) with p_field p_table.
endif.
else.
message e804(5g) with p_field p_table.
endif.
endif.
at selection-screen on value-request for p_field.
w_repid = sy-repid.
w_dynnr = sy-dynnr.
call function u2018DYNP_VALUES_READu2019
exporting
dyname = w_repid
dynumb = w_dynnr
tables
dynpfields = wt_dynp
exceptions
others = 1.
if sy-subrc = 0.
read table wt_dynp into ws_dynp index 1.
p_table = ws_dynp-fieldvalue.
call function u2018F4_DD_TABLE_FIELDSu2019
exporting
table = p_table
importing
result = p_field.
endif.
Start of processing
start-of-selection.
perform f_create_table using p_table.
perform f_select_table.
perform f_modify_table.
perform f_display_table using <itab>.
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form f_init_table
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_init_table.
Prepare free selection on table
perform f_table_def using p_table.
refresh it_tables.
is_tables-prim_tab = p_table.
append is_tables to it_tables.
clear: w_selid.
endform. u201Cf_init_table
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form f_init_selections
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_init_selections.
Init free selection dialog
call function u2018FREE_SELECTIONS_INITu2019
exporting
expressions = it_expr
importing
selection_id = w_selid
expressions = it_expr
tables
tables_tab = it_tables
fields_tab = it_fields
exceptions
others = 1.
endform. u201Cf_init_selections
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
FORM f_table_def *
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_table_def using in_tabname.
call function u2018DDIF_NAMETAB_GETu2019
exporting
tabname = p_table
importing
x030l_wa = is_x030l
tables
x031l_tab = it_x031l
exceptions
others = 1.
if is_x030l is initial.
table_error u2018does not exist or is not activeu2019.
elseif is_x030l-tabtype ne u2018Tu2019.
table_error u2018is not selectableu2019.
endif.
endform. u201Cf_table_def
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
FORM f_create_table *
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_create_table using in_tabname.
create data it_content type table of (in_tabname).
if sy-subrc = 0.
assign it_content->* to <itab>.
else.
write: u2018Error creating internal tableu2019.
stop.
endif.
endform. u201Cf_create_table
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
FORM f_select_table *
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_select_table.
if w_active = 0.
select * from (p_table)
into corresponding fields of table <itab>.
else.
Selection with parameters
call function u2018FREE_SELECTIONS_EX_2_WHEREu2019
exporting
expressions = it_expr
importing
where_clauses = it_where
exceptions
expression_not_supported = 1
others = 2.
read table it_where into is_where with key tablename = p_table.
select * from (p_table)
into corresponding fields of table <itab>
where (is_where-where_tab).
endif.
if sy-dbcnt = 0.
write: u2018No record selectedu2019.
stop.
endif.
endform. u201Cf_select_table
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
FORM f_modify_table *
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_modify_table.
field-symbols: <fld> type any.
loop at <itab> assigning <irec>.
if p_field is not initial.
assign component p_field of structure <irec> to <fld>.
if sy-subrc = 0.
call function u2018GENERIC_CONVERSION_EXIT_INPUTu2019
exporting
i_tabname = p_table
i_fieldname = p_field
input_text = p_value
importing
output_text = <fld>
exceptions
invalid_ddic_parameters = 1
invalid_input = 2
others = 3.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
endif.
if p_systm is not initial.
Default values for system fields
loop at it_x031l into is_x031l.
if is_x031l-dtyp = u2018CLNTu2019.
fixed_val sy-mandt.
elseif is_x031l-rollname = u2018ERDATu2019
or is_x031l-rollname = u2018ERSDAu2019
or is_x031l-rollname = u2018AEDATu2019
or is_x031l-rollname = u2018LAEDAu2019.
fixed_val sy-datum.
elseif is_x031l-rollname = u2018ERTIMu2019
or is_x031l-rollname = u2018AETIMu2019.
fixed_val sy-uzeit.
elseif is_x031l-rollname = u2018ERNAMu2019
or is_x031l-rollname = u2018AENAMu2019.
fixed_val sy-uname.
endif.
endloop.
endif.
endloop.
endform. u201Cf_modify_table
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
FORM f_display_table *
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form f_display_table using in_table.
data: ob_table type ref to cl_salv_table,
ob_event type ref to cl_salv_events_table,
cx_error type ref to cx_salv_msg.
try.
call method cl_salv_table=>factory
importing
r_salv_table = ob_table
changing
t_table = in_table.
catch cx_salv_msg into cx_error.
exit.
endtry.
if p_displ is initial and
p_field is not initial.
call method ob_table->set_screen_status
exporting
report = u2018ZBC_UPDATE_TABLEu2019
pfstatus = u2018STANDARDu2019
set_functions = ob_table->c_functions_all.
ob_event = ob_table->get_event( ).
create object ob_appl.
set handler ob_appl->on_user_command for ob_event.
else.
call method ob_table->set_screen_status
exporting
report = u2018SAPLSALVu2019
pfstatus = u2018STANDARDu2019
set_functions = ob_table->c_functions_all.
endif.
call method ob_table->display.
endform. u201Cf_display_table
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form user_command
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form user_command using in_command type salv_de_function.
data: l_messg type string,
l_answer type c.
data: ls_expr type string.
check in_command = u2018SAVEu2019.
l_messg = u2018Overwrite field for all selected records ?u2019.
call function u2018POPUP_TO_CONFIRMu2019
exporting
titlebar = u2018Update tableu2019
text_question = l_messg
default_button = u20182u2032
display_cancel_button = u2018 u2018
popup_type = u2018@1A@u2019
importing
answer = l_answer
exceptions
text_not_found = 1
others = 2.
if l_answer = u20181u2032.
concatenate p_field u2018= u201Du2019 into ls_expr
separated by space.
concatenate ls_expr p_value u201Du201D into ls_expr.
try.
update (p_table) set (ls_expr)
where (is_where-where_tab).
catch cx_sy_dynamic_osql_error.
rollback work.
message u2018Error during update!u2019 type u2018Iu2019.
endtry.
if sy-subrc = 0.
commit work.
endif.
endif.
endform. u201Cuser_command
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Include ZBC_QUERY_EVENTS
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
class lcl_handle_events definition deferred.
data: ob_appl type ref to lcl_handle_events.
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
CLASS lcl_handle_events DEFINITION
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
class lcl_handle_events definition.
public section.
methods:
on_user_command for event added_function of cl_salv_events
importing e_salv_function,
on_before_salv_function for event before_salv_function of cl_salv_events
importing e_salv_function,
on_after_salv_function for event after_salv_function of cl_salv_events
importing e_salv_function,
on_double_click for event double_click of cl_salv_events_table
importing row column,
on_link_click for event link_click of cl_salv_events_table
importing row column.
endclass. u201Clcl_handle_events DEFINITION
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
CLASS lcl_handle_events IMPLEMENTATION
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
class lcl_handle_events implementation.
method on_user_command.
perform user_command in program (sy-repid) if found
using e_salv_function.
endmethod. u201Con_user_command
method on_before_salv_function.
perform before_function in program (sy-repid) if found
using e_salv_function.
endmethod. u201Con_before_salv_function
method on_after_salv_function.
perform after_function in program (sy-repid) if found
using e_salv_function.
endmethod. u201Con_after_salv_function
method on_double_click.
perform double_click in program (sy-repid) if found
using row column.
endmethod. u201Con_double_click
method on_link_click.
perform link_click in program (sy-repid) if found
using row column.
endmethod. u201Con_single_click
endclass. u201Clcl_handle_events IMPLEMENTATION
thanks
karthik -
How do i open and control other programs using labview?
I'm presently trying to use labview to try to open and operate another program,but having much difficulty.The external program i'm using is called the Foundation program.
This Foundation program will use VHDL programming to create a virtual chip and then synthesising it.This program will then simulate the output of this VHDL program to verify that it is working as desired.Then the last stage is to download the whole VHDL program into a FPGA chip using a xilinx cable.
All this need to be done using a labview program - to open the Foundation program and then extract the saved file and then to execute the download command to cause the VHDL program to be downloaded onto the FPGA chip.How do i go
about doing all this?What is the first step i must do.Also all this have to be done thru networking..looks like its too difficult..I really need help.
graysI haven't done VHDL so pardon my ignorance.
LabVIEW can call external DLL via "Call Library Function" or C programs via "Code Interface Node", both located in "Advanced" function.
If your program is a DOS program, use "System Exec.vi" found in "Communication" function. If you need to format your DOS command prior to sending it, use the "Format Into String" function in "String" function palette.
Lastly, if you're trying to extract data, assuming it is text, use "File I/O" functions. If the data is binary, use "File I/O -> Binary File VIs".
Hope that answers most of your questions.
Shan Pin Koh -
Client/Server in one program (using multiple threads)?
Is there some examples out there of how to use a client and server in a single program using separate threads? Also, is it possible to start a third thread to control the packets, such as drop a random or specified number of packets (or match on specific data in a packet)?
Just trying to have a client send udp packets to a server (all on the same machine running from the same program) and want to be able to drop packets coming from the client side to the server side.
E.g.,
Here's an example that I found here: http://compnet.epfl.ch/tps/tp5.html
import java.io.<strong>;
import java.net.</strong>;
import java.util.<strong>;
/</strong>
* Server to process ping requests over UDP.
public class PingServer {
private static double lossRate = 0.3;
private static int averageDelay = 100; // milliseconds
private static int port;
private static DatagramSocket socket;
public static void main(String[] args) {
// Get command line arguments.
try {
if (args.length == 0) {
throw new Exception("Mandatory parameter missing");
port = Integer.parseInt(args[0]);
if (args.length > 1) {
lossRate = Double.parseDouble(args[1]);
if (args.length > 2) {
averageDelay = Integer.parseInt(args[2]);
} catch (Exception e) {
System.out.println("UDP Ping Server");
System.out.println("Usage: java PingServer port [loss rate] [average delay in miliseconds]");
return;
// Create random number generator for use in simulating
// packet loss and network delay.
Random random = new Random();
// Create a datagram socket for receiving and sending UDP packets
// through the port specified on the command line.
try {
socket = new DatagramSocket(port);
System.out.println("UDP PingSever awaiting echo requests");
} catch (SocketException e) {
System.out.println("Failed to create a socket");
System.out.println(e);
return;
// Processing loop.
while (true) {
// Create a datagram packet to hold incoming UDP packet.
DatagramPacket request = new DatagramPacket(new byte[1024], 1024);
// Block until the host receives a UDP packet.
try {
socket.receive(request);
} catch (IOException e) {
System.out.println("Error receiving from socket");
System.out.println(e);
break;
// Print the received data.
printData(request);
// Decide whether to reply, or simulate packet loss.
if (random.nextDouble() < lossRate) {
System.out.println(" Reply not sent.");
continue;
// Simulate network delay.
try {
Thread.sleep((int) (random.nextDouble() * 2 * averageDelay));
} catch (InterruptedException e) {}; // Ignore early awakenings.
// Send reply.
InetAddress clientHost = request.getAddress();
int clientPort = request.getPort();
byte[] buf = request.getData();
DatagramPacket reply = new DatagramPacket(buf, buf.length,
clientHost, clientPort);
try {
socket.send(reply);
} catch (IOException e) {
System.out.println("Error sending to a socket");
System.out.println(e);
break;
System.out.println(" Reply sent.");
* Print ping data to the standard output stream.
private static void printData(DatagramPacket request) {
// Obtain references to the packet's array of bytes.
byte[] buf = request.getData();
// Wrap the bytes in a byte array input stream,
// so that you can read the data as a stream of bytes.
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
// Wrap the byte array output stream in an input stream reader,
// so you can read the data as a stream of characters.
InputStreamReader isr = new InputStreamReader(bais);
// Wrap the input stream reader in a buffered reader,
// so you can read the character data a line at a time.
// (A line is a sequence of chars terminated by any combination of \r
// and \n.)
BufferedReader br = new BufferedReader(isr);
// We will display the first line of the data.
String line = "";
try {
line = br.readLine();
} catch (IOException e) {
// Print host address and data received from it.
System.out.println("Received echo request from "
+ request.getAddress().getHostAddress() + ": " + line);
}I'm looking to do the "processing loop" in a separate thread, but I'd also like to do the client in a separate thread
So you're saying, just put the client code in a separate class and start the thread and that's it? As far as the packet rate loss thread, is this possible to do in another thread? -
Hi! I'm a Windows XP convert... switched to an imac about 4 months ago and am LOVIN' it As a graphics designer I did use a feature on my Windows machine which I really miss on my mac... beaing able to see a preview of one of the images in a folder on top of the folder icon. In other words, in Windows, you can see the first image that is inside the folder as an icon on the folder itself. Is there a way to do this on the mac? Maybe some software program that will do it? Thanks for you help!
It would be brilliant if Apple could make picture folders behave like events in iPhoto. You could see a photo on the folder, and also mouse over it to change pictures.
But no, there's not an application I'm aware of that does this. You can manually make a picture the folder icon, but it's a tedious process.
Unfortunately this is another example of how dated and worn out the Mac's interface is. The concept of using a file folder as the icon for a directory of images is so 80's. You could use coverflow, but that only helps once you're in the directory itself. Or use iPhoto or Aperture, although they just do photos. Or try Lyn as an alternative: it has a sort of iTunes-like interface, and makes it easy to organize photos without having to put them in iPhoto. And it can display photos that are already in Libraries.
But you'd probably need a Finder alternative. I use Leap, which displays any type of document. It also does tagging, which is another huge omission in the Finder. More like Windows Explorer (although still no photo on folder icons).
Another very stylish Finder alternative, especially useful for pictures, is FileBrowse. I don't know why it hasn't gotten more attention. It DOES put photo previews on the folders it shows. And allows one-click expansion to show the photo enlarged. It's super fast, and even allow you to group/sort by camera or flash! It really has to be seen to be appreciated. It works in Lion, although it doesn't seem to be have been updated lately. http://www.filebrowse.com/index.html
Rob -
Reading & writing to file using ArrayList String incorrectly (2)
I have been able to store two strings (M44110|T33010, M92603|T10350) using ArrayList<String>, which represent the result of some patient tests. Nevertheless, the order of these results have been stored correctly.
E.g. currently stored in file Snomed-Codes as -
[M44110|T33010, M92603|T10350][M44110|T33010, M92603|T10350]
Should be stored and printed out as -
M44110|T33010
M92603|T10350
Below is the detail of the source code of this program:
import java.io.*;
import java.io.IOException;
import java.lang.String;
import java.util.regex.*;
import java.util.ArrayList;
public class FindSnomedCode {
static ArrayList<String> allRecords = new ArrayList<String>();
static public ArrayList<String> getContents(File existingFile) {
StringBuffer contents = new StringBuffer();
BufferedReader input = null;
int line_number = 0;
int number_of_records = 0;
String snomedCodes = null;
ArrayList<String> complete_records = new ArrayList<String>();
try {
input = new BufferedReader( new FileReader(existingFile) );
String current_line = null;
while (( current_line = input.readLine()) != null) {
// Create a pattern to match for the "\"
Pattern p = Pattern.compile("\\\\");
// Create a matcher with an input string
Matcher m = p.matcher(current_line);
boolean beginning_of_record = m.find();
if (beginning_of_record) {
line_number = 0;
number_of_records++;
} else {
line_number++;
if ( (line_number == 2) && (current_line.length() != 0) ) {
snomedCodes = current_line;
System.out.println(snomedCodes);
complete_records.add(current_line);
catch (FileNotFoundException ex) {
ex.printStackTrace();
catch (IOException ex){
ex.printStackTrace();
finally {
try {
if (input!= null) {
input.close();
catch (IOException ex) {
ex.printStackTrace();
return complete_records;
static public void setContents(File reformatFile, ArrayList<String> snomedCodes)
throws FileNotFoundException, IOException {
Writer output = null;
try {
output = new BufferedWriter( new FileWriter(reformatFile) );
for (String index : snomedCodes) {
output.write( snomedCodes.toString() );
finally {
if (output != null) output.close();
static public void printContents(File existingFile) {
StringBuffer contents = new StringBuffer();
BufferedReader input = null;
int line_number = 0;
int number_of_records = 0;
String snomedCodes = null;
try {
input = new BufferedReader( new FileReader(existingFile) );
String current_line = null;
while (( current_line = input.readLine()) != null)
System.out.println(current_line);
catch (FileNotFoundException ex) {
ex.printStackTrace();
catch (IOException ex){
ex.printStackTrace();
finally {
try {
if (input!= null) {
input.close();
catch (IOException ex) {
ex.printStackTrace();
public static void main (String args[]) throws IOException {
File currentFile = new File("D:\\dummy_patient.txt");
allRecords = getContents(currentFile);
File snomedFile = new File( "D:\\Snomed-Codes.txt");
setContents(snomedFile, allRecords);
printContents(snomedFile);
}There are 4 patient records in the dummy_patient.txt file but only the 1st (M44110|T33010) & 3rd (M92603|T10350) records have results in them. The 2nd & 4th records have blank results.
Lastly, could someone explain to me the difference between java.util.List & java.util.ArrayList?
I am running Netbeans 5.0, jdk1.5.0_09 on Windows XP, SP2.
Many thanks,
Netbeans Fan.while (snomedCodes.iterator().hasNext())
output.write( snomedCodes.toString() );
}Here you have some kind of a list or something (I couldn't stand to read all that unformatted code but I suppose you can find out). It has an iterator which gives you the entries of the list one at a time. You keep asking if it has more entries -- which it does -- but you never get those entries by calling the next() method, so it always has all the entries still available.
And your code inside the loop is independent of the iterator, so it's rather pointless to iterate over the entries and output exactly the same data for each entry. Even if you were iterating correctly.
Maybe you are looking for
-
Since downloading Itunes 11.0.1 (12), Itunes can't locate or play many songs but the same songs still play on my synched iPod. I have a MacBook Air, Lion OS, Itunes version 11.0.1 (12). I didn't see this problem with older versions of Itunes. I do
-
I have Samsung Reality cell phone and I have moved all my pictures from my phone to card. Once I inserted SD card into laptop, pop-up says the card is not formatted. The computer will not read card and phone now will not read card. Are these pictures
-
How can I backup an external hard drive using Time Machine?
How can I backup an external hard drive connected to my MacBook Pro using Time Machine?
-
Pass info from safari to X11 application
Hi, I am wanting to pass some data from a web page (viewed using Safari) to an X11 application and I was wondering if anyone can suggest how to do this ? The data in question is ascii text and represents a script which is passed to a molecule viewer
-
Iphone 3g not showing up in itunes?
My 3g is not showing up in itunes! help!!!